Blogger Information
Blog 5
fans 0
comment 0
visits 4426
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
MySQL 主从复制实操
月影的博客
Original
776 people have browsed it

本文转载于:https://laravel-china.org/articles/18189

基础信息

主: 192.168.0.1 root pwd1
从: 192.168.0.2 root pwd2

备份

复制 两台服务器的/etc/mysql/mysql.conf.d/mysqld.cnf 到 /etc/mysql/mysql.conf.d/mysqld.cnf.bak 便于数据恢复

主服务器配置

# bind-address           = 127.0.0.1server-id               = 1log_bin                 = /var/log/mysql/mysql-bin.log

注释掉bind-address到127.0.0.1,允许远程连接,打开server-id和log二进制文件的注释

mysql> show master status;

获取mysql-bin的file信息和position信息 例如: mysql-bin.000001 9937

grant replication slave on *.* to 'repl'@'192.168.0.2' identified by 'replpwd';

创建从库的登录用户,并且授予slave权限

从服务器配置

server-id               = 2replicate-do-db=buildings

打开server-id的注释,手动修改不同于主服务器
我要配置的是单数据库的复制,所以我配置了一个我需要的 replicate-do-db

change master to master_host='192.168.0.1', master_user='repl', master_password='replpwd', master_log_file='mysql-bin.000001', master_log_pos=9937;
mysql> show slave status \G;  Slave_IO_Running 和 Slave_SQL_Running 值 都为 Yes  说明就成功了

注意,配置中,可以设置只复制哪些库,哪些表,也可以设置忽略哪些库和哪些表,但是 replicate-do-db和replicate-ignore-db只能存在这一种,否则不会生效

常用命令

mysql>  stop slave; // 停止复制mysql>  reset slave; // 重置复制mysql>  start slave; // 开启复制mysql>  show master status; // 显示主库状态 mysql>  show slave status\G // 显示从库状态

参考文档


Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!