标签:mysql 主从配置
mysql主从服务器:
主:192.168.121.128
从:192.168.121.129
主从服务器分别作以下操作:
版本一致
初始化表,并在后台启动mysql
修改root的密码
mysqladmin -u root password "newpass"
mysql主从文件的配置:
#master主配置文件添加以下2行:
cat /etc/my.cnf
log-bin=mysql-bin//[必须]启用二进制日志
server-id=128//[必须]服务器唯一ID,默认是1,一般取IP最后一段
#slave配置文件添加以下2行:
cat /etc/my.cnf
log-bin=mysql-bin//[不是必须]启用二进制日志
server-id=129 //[必须]服务器唯一ID,默认是1,一般取IP最后一段
主库操作:
#mysql -uroot -p
GRANT REPLICATION SLAVE ON *.* to ‘mysync‘@‘192.168.121.129‘ identified by ‘123456‘;
mysql> show master status;
+------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000001 | 264 | | |
+------------------+----------+--------------+------------------+
1 row in set (0.00 sec)
从库操作:
mysql> change master to master_host=‘192.168.121.128‘,master_user=‘mysync‘,master_password=‘123456‘,master_log_file=‘mysql-bin.000001‘,master_log_pos=
Query OK, 0 rows affected (0.03 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> show slave status;
#看到下面信息证明主从ok。
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
本文出自 “LINUX Super梦” 博客,请务必保留此出处http://215687833.blog.51cto.com/6724358/1892751
标签:mysql 主从配置
原文地址:http://215687833.blog.51cto.com/6724358/1892751