linux__mariadb主从复制(centos)
1.准备俩台服务器
主服务器: 192.168.12.249
从服务器: 192.168.12.200
2.
systemctl stop mariadb
3.
[mysqld] server-id=1 ##主从复制的sever-id是不一致的 log-bin=qishi-logbin ##启用二进制日志
4.启动主服务器mairadb
systemctl start mariadb
5.
create user 'lijun'@'%' identified by 'lj666'; #%表示的是, 允许任何ip进行访问 待定?
然后授权
grant replication slave on *.* to 'lijun'@'%'; ##给从库账号设置权限
然后检查
use mysql
select user,host from mysql.user; ##作为检查进行使用, 进一步确认
#查看权限
show grants for lijun@'%';
6.从库上配置
1.关闭数据库服务 systemctl stop mariadb 2.vim /etc/my.cnf(添加以下配置) [mysqld] character-set-server=utf8 collation-server=utf8_general_ci log-error=/var/log/mysqld.log [client] default-character-set=utf8 [mysql] default-character-set=utf8 server-id=3 #id和主库id不一致即可 read-only=true #只读 3.重启 systemctl restart mariadb 4.将主库导出的数据库文件拷贝过来 scp 192.168.12.249:/opt/qishimaster.sql /opt/ 5.导入主库数据库文件 mysql -u root -p source /opt/qishimaster.sql 6.配置复制的参数,Slave从库连接Master主库的配置 mysql > change master to master_host='192.168.11.212', master_user='lijun', master_password='lj666', master_log_file='qishi_logbin.000002', master_log_pos=245; 7.启动从库的同步开关 start slave; 8.查看复制状态 show slave status\G; 9.最后切换到主库上,需要登陆上mysql后再操作的 unlock tables;
7.相关连接
https://www.cnblogs.com/tiger666/articles/10259269.html