欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  科技

Mysql主主配置

程序员文章站 2023-11-08 10:10:16
1.vim /etc/my.cnf 2.service mysqld restart 3.进入 Mysql 4.进入从服务器 5.vim /etc/my.cnf 6.进入从Mysql 配置主主,从第6步在主服务器上重复操作 ......

 1.vim /etc/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=1
log_bin=mysqlbin
relay_log=relaylog

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

 2.service mysqld restart

 3.进入 mysql

mysql> grant all on *.* to tom@'192.168.146.%' identified by '123';
query ok, 0 rows affected (0.00 sec)

mysql> flush privileges;
query ok, 0 rows affected (0.00 sec)

Mysql主主配置

 4.进入从服务器

 5.vim /etc/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=2
log_bin=mysqllog
relay_log=mysqlrelay

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

 6.进入从mysql

mysql> stop slave;
query ok, 0 rows affected, 1 warning (0.00 sec)

mysql> change master to master_host='192.168.146.6', master_user='tom',master_password='123',master_log_file='mysqlbin.000003',master_log_pos=315;
query ok, 0 rows affected (0.39 sec)

mysql> start slave;
query ok, 0 rows affected (0.00 sec)

mysql> show slave status \g;

  Mysql主主配置

 

 

 配置主主,从第6步在主服务器上重复操作