在主服务器上登陆数据库,并配置数据库
创建复制账号,replusr,给予最小权限replication slave
mysql -h127.0.0.1 -uroot -P3306
mysql> set old_passwords=0;
mysql> create user 'replusr'@'%' identified by 'password';
mysql> grant replication slave on *.* to 'replusr'@'%';
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'password' WITH GRANT OPTION;
mysql> SHOW MASTER STATUS;
+-------------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+-------------------+----------+--------------+------------------+-------------------+
| master-bin.000003 | 333 | | | |
+-------------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)
需要用到上面标注红色的两个参数
在从服务器(134.96.247.48)上登陆数据库,并配置数据库
mysql -h127.0.0.1 -uroot -P3306
mysql> set old_passwords=0;
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'password' WITH GRANT OPTION;
mysql>CHANGE MASTER TO MASTER_HOST='134.96.247.47',MASTER_USER='replusr',MASTER_PASSWORD='password' ,MASTER_LOG_FILE='master-bin.000003',MASTER_LOG_POS=333;
mysql> start slave;
mysql> show slave status G;
在打印出来的状态下,查看以下两个参数的值:
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
如果这两个参数的值都是yes,则运行正常,可以在master数据库上添加一个数据库或者添加一张表,检查slave数据库上是否存在。
如果 这两个参数有任何一个不是 Yes,则说明存在问题。可以查看slave上的数据库错误日志文件查看错误原因。