当前位置:Gxlcms > 数据库问题 > mysql主从配置

mysql主从配置

时间:2021-07-01 10:21:17 帮助过:2人阅读

1)修改主库配置文件,在[mysqld]下面添加: log-bin=mysql-bin server-id = 1 2)修改从库配置文件,在[mysqld]下面添加:: relay-log=mysql-relay server-id = 152 2主库上设置同步的账号: mysql> grant replication client,replication slave on *.* to ‘repl‘@‘192.%.%.%‘ identified by ‘repl‘; Query OK, 0 rows affected (0.00 sec) mysql> flush privileges; Query OK, 0 rows affected (0.00 sec) 3查看主库的bin-log信息, mysql> show master status; +------------------+----------+--------------+------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | +------------------+----------+--------------+------------------+ | mysql-bin.000001 | 1526 | | | +------------------+----------+--------------+------------------+ 1 row in set (0.00 sec) 4在从库上设置: mysql> change master to -> master_host=‘192.168.12.151‘, -> master_user=‘repl‘, -> master_password=‘repl‘, -> master_log_file=‘mysql-bin.000001‘, -> master_log_pos=1526; mysql> start slave; 5到此主从基本配置完毕,我们需要在从库上show slave status观察几个值,确认是否正常。 mysql> show slave status\G *************************** 1. row *************************** Slave_IO_State: Waiting for master to send event Slave_IO_Running: Yes Slave_SQL_Running: Yes 6确认正常之后,在主库上修改数据,观察从库是否进行改变。

人气教程排行