主数据库配置:vim  /etc/my.cnf
server_id=146 #一般设置ip最后一位
log-bin=mysql-bin #开启bin-log
binlog_do_db=test #生成test数据库
binlog_do_db=sss #生成sss数据库
binlog_ignore_db=sss #忽略数据库
#查看配置是否生效 show VARIABLES like
'%server_id%' show master status; 从数据库配置:vim /etc/my.cnf server_id=132 log-bin=mysql-bin #执行sql change master to master_host='master_db_ip',master_user='root',master_password='pwd',master_log_file='mysql-bin.000001',master_log_pos=892; #查看配置是否生效 show VARIABLES like '%server_id%' show slave status; stop SLAVE start slave


#添加mysql只读用户

GRANT SELECT ON 数据库.* TO '用户名'@'%' IDENTIFIED BY "密码";

FLUSH PRIVILEGES;
#查看用户

SELECT DISTINCT a.`User`,a.`Host`,a.password_expired,a.password_last_changed,a.password_lifetime,a.* FROM mysql.user a;



 

#相关sql
show slave status;
stop slave ;
start slave ;
#因为gtid没开启导致io为no可以尝试试执行 set global enforce_gtid_consistency=on; set global gtid_mode=OFF_PERMISSIVE;
 set global gtid_mode=ON;
show VARIABLES like '%server_id%' show global variables like 'gtid_mode'; 
show global variables like 'GTID_EXECUTED';
set global GTID_PURGED='master的';

  

# 查找执行慢的sql
show processlist
show full processlist;
show variables  like '%slow_query_log%';


#CREATE TABLE kf05_2020 LIKE kf05;

#INSERT INTO kf05_2020 SELECT * FROM kf05;

#delete from kf06 where KF06006 <'2021-01-01 00:00:00'