mysql主从配置

xiaoxiao2021-02-28  59

创建用户(双方主从库)

GRANT ALL ON *.* to 'username'@'%' identified by 'password'; 

设置主数据库为只读

flush tables with read lock;

主库 my.cnf配置 log-bin=mysql-bin server-id=1 binlog-do-db=同步数据库名 expire_logs_days=3

log_bin_trust_function_creators=1

 查看主库状态

SHOW MASTER STATUS;

从库 my.cnf配置 server-id=2 replicate-do-db=同步数据库名

log_bin_trust_function_creators=1

从库命令:

stop slave;

change master to master_host='主库IP',master_port=3306,master_user='username',master_password='password',master_log_file='查询主库(SHOW MASTER STATUS;命令获得)',master_log_pos=查询主库(SHOW MASTER STATUS;命令获得);

START SLAVE;

查看同步状态

SHOW SLAVE STATUS\G

主库命令: 解锁主库只读 unlock tables;

 

导出主库数据:      mysqldump -u root -p facecast_produc>facecast_product.sql      将主库sql文件传到从库         scp -P 9823 facecast_product.sql root@104.243.131.6:/root/  (会要求输入从库系统密码)      在从库导入主库sql文件     mysql -u 用户名 -p  数据库名 < 数据库名.sql

转载请注明原文地址: https://www.6miu.com/read-2622340.html

最新回复(0)