您的位置:首页 > 数据库 > MySQL

mysql主从复制

2015-09-08 16:36 627 查看
关闭防火墙和selinux

主(master)服务器:192.168.0.4
从(slave)服务器:192.168.0.5

首先配置主服务器:
1.[root@localhost etc]# vim my.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
server-id=4
log-bin=mysql-bin

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

2.grant replication slave on *.* to tongbu@192.168.0.5 identified by '123456';

3.[root@localhost etc]# service mysqld restart

4.mysql> show master status;
+------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000001 | 106 | | |
+------------------+----------+--------------+------------------+
1 row in set (0.00 sec)

其次配置从服务器:
1.[root@localhost etc]# vim my.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
server-id=5

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

2.mysql>change master to master_host='192.168.0.5',master_user='tongbu',master_password='123456',master_log_file='mysql-bin.000001',master_log_pos=106;

3.mysql> start slave;

4.mysql> show slave status\G; Slave_IO_Running: Yes Slave_SQL_Running: Yes 出现以上两个Yes,配置完成。

同步成功,在主上创建库和表,去从上验证是否同步过来。------2015-9-8--------

本文出自 “努力!奋斗!” 博客,请务必保留此出处http://026mm.blog.51cto.com/8783374/1692808
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: