数据库读写分离


CREATE USER ‘username‘@’%’ IDENTIFIED BY ‘password’;
username:用户名
%:指定该用户在哪个主机上可以登陆,如果是本地用户可用localhost,如果想让该用户可以从任意远程主机登陆,可以使用通配符%
password:用户密码

GRANT REPLICATION SLAVE ON *.* to ‘username‘@’%’;

log-bin=mysql-bin //启用二进制日志 (主数据库必须)
server-id=1 //服务器唯一ID,默认是1,一般取IP最后一段(必须)(不同服务器的server-id应不同)

show master status;
1
2
File			Position		Binlog_Do_DB		Binlog_Ignore_DB
mysql-bin.000004 308



change master to master_host=’主数据库ip’,master_user=’username’,master_password=’password’, master_log_file=’mysql-bin.000004’,master_log_pos=308;
username:主数据库创建的用户名
password:主数据库创建的用户的密码
master_log_file:主数据库的状态的File
master_log_pos:主数据库的状态的Position


*** row ***
Slave_IO_State: Waiting for master to send event
Master_Host: 10.20.14.6(主数据库ip)
Master_User: repl(用户名)
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000004
Read_Master_Log_Pos: 308
Slave_IO_Running: Yes(数据同步)
Slave_SQL_Running: Yes(sql同步)