How to install two versions of MYSQL on one computer (windows)

1. The same computer needs to install two MYSQL, take mysql-5.7.39 and mysql-8.0.30 as an example;

1. Download: https://downloads.mysql.com/archives/community/  select the corresponding version;

2. Download and decompress the corresponding installation package;

3. Install mysql-5.7.39 first, unzip it and put it into the corresponding disk, and create a new data and uploads folder and my.ini file;

my.ini content: the file format is ini, edit the corresponding path

[mysqld]
port=3306
character_set_server=utf8
basedir=C:\mysql-5.7.39
datadir=C:\mysql-5.7.39\data
server-id=1
sql_mode=NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
lower_case_table_names=1
innodb_file_per_table = 1
log_timestamps=SYSTEM

log-error = error.log
slow_query_log = 1
slow_query_log_file = slow.log
long_query_time = 5
log-bin = binlog
binlog_format = row
expire_logs_days = 15
log_bin_trust_function_creators = 1
secure-file-priv=C:\mysql-5.7.39\uploads

[client]
default-character-set=utf8

 4. In the environment variable-path configuration variable:

5. Initialize the database: (run cmd as an administrator);

Switch to C:\mysql-5.7.39 and execute: mysqld --initialize-insecure

Then enter the bin to execute the installation: mysqld –install MySQL57

Start MySQL: net start mysql57  or right-click in the task manager to start;

6. Set login password

Use mysql -uroot to directly log in to the password;

SET PASSWORD FOR 'root'@'localhost'= "root-pas";
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root-pas' WITH GRANT OPTION;
FLUSH PRIVILEGES;

So far, mysql-5.7.39 installation is complete.

2. Install mysql-8.0.30 (stop mysql-5.7.39 first)

1. Unzip the compressed package, create new data, uploads and my.ini (same steps as mysql57)

2. Modify my.ini to modify the port to 3307 and the character set to: character_set_server=utf8mb4;

add: shared-memory;

 3. Also configure environment variables (same as above) and run CMD as an administrator;

Switch to E:\mysql-8.0.30\bin and execute:

Execute: mysqld --defaults-file=E:\mysql-8.0.30\my.ini --initialize --console   (remember the temporary password)

Execute: mysqld install MySQL8

4. Modify the registration list path: \HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\MYSQL8 Modify the path (the default is the path of the first installation of 5.7)

Start mysql8 (the method is the same as above)

5. The installation of mysql-8.0.30 is completed, log in and modify it through the temporary password;

6. Temporary password cannot be entered, enter without password: add skip-grant-tables under [mysqld] in my.ini and restart, log in and modify

use mysql ;

Input: update user set authentication_string='' where user='root';   set authentication_string to empty;

Change the password, still report an error;

First refresh the privilege table: mysql> flush privileges;

Change the password again successfully: SET PASSWORD FOR 'root'@'localhost'= "root-pas";

Flush: FLUSH PRIVILEGES;

Remove skip-grant-tables in my.ini and restart, log in with password, success.

 ===================================================================

Problems encountered during installation:

1. Mysql8 cannot be started when it is installed, reconfigure the environment variables and the path of the registration list; it starts again successfully, but it stops automatically after starting. . . . .

2. Check the data log, there is an online prompt to comment out #sql_mode=NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION, MySQL8 does not have this, and an error is still reported after commenting. . . . .

3. Check whether the port is occupied, netstat -ano|findstr 3307 is still not occupied;

4. Continue to Baidu, go to the bin as an administrator with cmd E:\mysql-8.0.30\bin> mysqld --install prompts success,
Service successfully installed. The service is ok;

5. Continue to execute: mysqld --console  prompts an error:

  [ERROR] [MY-010131] [Server] TCP/IP, --shared-memory, or --named-pipe should be configured on NT OS

Solution: Add shared-memory (as shown above) under [mysqld] in my.ini, restart the service, and run normally;

# Another method is to delete the data folder and re-execute the command to register and automatically generate data (not tested)

6. One is that the password cannot be logged in, you need to refresh the authority first, and then change the password .

7. Log in to mysql in the corresponding bin directory, and both display mysql8; first stop mysql8, log in to mysql57 and then start mysql8, and the login display is normal;

Guess you like

Origin blog.csdn.net/g100568999/article/details/128301063