Install MySQL (MySQL8.0 is used here). Disable the firewall or enable port 3306
The main library: 192.168.10.151
From the library: 192.168.10.152
1. Master library [mater] configuration
Modify the Master configuration file
/etc/my.cnf vim /etc/my.cnfCopy the code
Add server_id, log_bin to my.cnf configuration file, where server_id is a number and the value of log_bin is arbitrary (usually set to 1), I set master_log, the value of the variable is the log file name, Is the body of the log file name. The MySQL database automatically adds the file name suffix and file type.
Select Last_IO_Error from MySQL8.0 where Last_IO_Error: Last_IO_Error: Last_IO_Error: Last_IO_Error: Last_IO_Error: Last_IO_Error: Last_IO_Error: Last_IO_Error: Error connecting to master ‘[email protected]:3306’ – retry-time: 60 retries: 1 message: Authentication plugin ‘caching_sha2_password’ reported error: Authentication requires secure connection.
my.cnf
Server_id =1, log_bin=master_log, user=mysql (mysql user group and user), add authentication, or do not add authentication.
Restart MySQL and configure MySQL master
MySQL service mysqld restartCopy the code
Access to the MySQL
mysql -uroot -p123456
Copy the code
Specify authentication when creating a user, otherwise the following steps will fail. In MySQL8.0, implicit creation is not available, and you need to create it in authorization first
Create user 'slave'@'192.168.10.152' identified with caching_sha2_password by '123456'; create user 'slave'@'192.168.10.152' identified with caching_sha2_password by '123456'; Grant all PRIVILEGES on *.* to 'slave'@'192.168.10.152' with grant option; ## Refresh PRIVILEGES;Copy the code
192.168.10.152 is the IP address of the MySQL secondary library. Use caching_sha2_password or mysql_native_password. The password is 123456.
Change the authentication to mysql_native_password
Alter user 'slave'@'192.168.70.152' IDENTIFIED with mysql_native_password by '123456';Copy the code
View user and master information
## select mysql from mysql; Select host,user from user; ## show Master status;Copy the code
2. Configure the slave library
Modifying slave Configuration
Path: / etc/my CNF, using vim/etc/my CNF command to enter to my. The CNF file, add inside server_id = 2, here’s server_id value should be greater than the value of the main library server_id, you need to add is: Server_id =2; user=mysql;
my.cnf
Restarting the MySQL service
service mysqld restart
Copy the code
Log on to the MySQL
mysql -uroot -p123456
Copy the code
Configure information about the slave library
The data to be modified is based on the Master information. The IP address is the IP address of the Master physical server. The user name and password are the user name and password provided by the Master for accessing the Slave. The log files are provided by the Master library information viewed in Master. Run the show Master status command to view the log file name.
Stop slave ## Configure change master to Master_host = '192.168.70.151, master_user =' slave ', master_password = '123456', master_log_file = 'master_log. 000001';Copy the code
192.168.70.151: IP address of the primary library
Slave: user added in the master database, master_log.000001, master database show master status. Displayed file
Enable the slave function
start slave; ## show slave status;Copy the code
The absence of errors in the figure above means that there are no other problems from the library. If there are errors, it is usually due to authentication problems or permissions issues. The problem that arises next is one of authentication. Modify the user authentication function
Change the authentication function to mysql_native_password by, and then reconfigure the slave database
Alter user 'slave'@'192.168.70.152' IDENTIFIED with mysql_native_password by '123456';Copy the code