5、在主服务器上建立帐户并授权slave:
# mysql -uroot -p123456
mysql>GRANT REPLICATION SLAVE ON *.* to ‘clevercode‘@‘%‘ identified by ‘q123456‘; //一般不用root帐号,“%”表示所有客户端都可能连,只要帐号,密码正确,此处可用具体客户端IP代替,如192.168.145.226,加强安全。
6、登录主服务器的mysql,查询master的状态
mysql> show master status;
+------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000011 | 248 | | |
+------------------+----------+--------------+------------------+
1 row in set (0.00 sec)
注:执行完此步骤后不要再操作主服务器MYSQL,防止主服务器状态值变化
7、配置从服务器Slave:
mysql>stop slave;
mysql>change master to master_host=‘192.168.142.131‘,master_user=‘clevercode‘,master_password=‘q123456‘,
master_log_file=‘mysql-bin.000011‘,master_log_pos=248; //注意不要断开,248数字前后无单引号。
2、从服务器Mysql查询:
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| db_clevercode |
| mysql |
| performance_schema |
| test |
+--------------------+
5 rows in set (0.00 sec)
mysql> use db_clevercode;
Database changed
mysql> select * from tb_test;
+------+------------+
| id | name |
+------+------------+
| 1 | clevercode |
+------+------------+
1 row in set (0.01 sec)