Server ready
Ready server Server1 and Server2, needs to change its port if it is installed on the same server mysql words.
Uninstall mysql
Before you install mysql must first check had not been installed on the host, if installed, then you must first uninstall.
Install mysql
Download package:
wget https://repo.mysql.com//mysql80-community-release-el7-1.noarch.rpm
Local installation:
yum localinstall mysql80-community-release-el7-1.noarch.rpm
Install mysql:
yum install mysql-community-server
To boot:
systemctl enable mysqld
systemctl daemon-reload
Start mysql:
systemctl start mysqld
The above steps to install a good mysql8.
Obtain temporary password of mysql:
grep 'temporary password' /var/log/mysqld.log
Login mysql:
mysql -uroot -p
Will be prompted for a password, enter the temporary password before you can log acquired.
At this point you need to modify the mysql password, or else will be forced to step after prompt you need to change your password:
ALTER USER 'root'@'localhost' IDENTIFIED BY '121b33dAj934J1^Sj9ag';
mysql8 default there are requirements on the strength of the password, you need to set a little complicated, or else will prompt an error.
Refresh configuration:
FLUSH PRIVILEGES;
Master-slave configuration
Before the need to ensure consistent master-slave configuration of two mysql database to be synchronized state.
the Lord
In the default configuration file /etc/my.cnf
under.
New configuration in the configuration file:
[mysqld]
## 同一局域网内注意要唯一
server-id=100
## 开启二进制日志功能,可以随便取(关键)
log-bin=mysql-bin
After modifying the configuration need to restart to take effect:
service mysql restart
Once rebooted mysql:
mysql -uroot -p
Create a user in the master database data synchronization, grant user permissions slave REPLICATION SLAVE and REPLICATION CLIENT privilege for the primary synchronization between the data from the database.
CREATE USER 'slave'@'%' IDENTIFIED BY '@#$Rfg345634523rft4fa';
GRANT REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO 'slave'@'%';
Statement %
on behalf of all server users can use this, if you want to specify a particular ip, will %
be changed to ip.
Check the status of the main mysql:
show master status;
It was recorded File
and Position
the values, and does not perform other operations in order to avoid Position
changes.
From
In the my.cnf
new configuration:
mysqld]
## 设置server_id,注意要唯一
server-id=101
## 开启二进制日志功能,以备Slave作为其它Slave的Master时使用
log-bin=mysql-slave-bin
## relay_log配置中继日志
relay_log=edu-mysql-relay-bin
After modifying the configuration need to restart to take effect:
service mysql restart
Once rebooted mysql:
mysql -uroot -p
change master to master_host='172.17.0.2', master_user='slave', master_password='@#$Rfg345634523rft4fa', master_port=3306, master_log_file='mysql-bin.000001', master_log_pos= 2830, master_connect_retry=30;
MASTER_HOST : Master Address
MASTER_PORT : Master of the port number
MASTER_USER : user data for synchronization
master_password : used to synchronize the user's password
MASTER_LOG_FILE : Specifies Slave start copying data from which log file, i.e., File field value in the above-mentioned
master_log_pos value from which to start reading Position, Position i.e. the above-mentioned fields:
master_connect_retry : If the connection fails, retry interval, in seconds, default is 60 seconds
In the view from the mysql master-slave synchronization status:
show slave status \G;
At this time SlaveIORunning and SlaveSQLRunning are No, because we have not turned on the master-slave replication process.
Open master-slave replication:
start slave;
View synchronization status again:
show slave status \G;
Yes SlaveIORunning and SlaveSQLRunning are the main explanation has been turned from a copy.
If SlaveIORunning been the Connecting, there are four kinds of the following reasons:
1, the network is, check the ip port
2, the password is wrong, check for synchronization user name and password
3, pos wrong, check the Master of Position
4, mysql8 specific problems caused by the password rules:
ALTER USER 'slave'@'%' IDENTIFIED WITH mysql_native_password BY '@#$Rfg345634523rft4fa';
The password rules changed to: mysql_native_password
If you need to specify which database you want to master-slave synchronization, you can master the my.cnf
added configuration:
binlog-do-db:指定mysql的binlog日志记录哪个db
Or slave of my.cnf
adding configuration:
replicate-do-db=需要复制的数据库名,如果复制多个数据库,重复设置这个选项即可 replicate-ignore-db=需要复制的数据库名,如果复制多个数据库,重复设置这个选项即可
If you want to synchronize all database tables and in the implementation of the mysql:
STOP SLAVE SQL_THREAD;
CHANGE REPLICATION FILTER REPLICATE_DO_DB = ();
start SLAVE SQL_THREAD;
If the above steps have problems, you can view the log:
/etc/log/mysqld.log
Reproduced in: https: //www.jianshu.com/p/4786164c1c09