=================================
只是本人在搭建MYSQL主从服务器的笔记 ,不一定很好,高手可以飘过
=================================
双主架构 master A <--> master B
第一步;改配置文件 ->默认位置/etc/my.cnf
master的
[mysqld]
log-bin=mysql-bin # 开启二进制日志
server-id=2 #ID的区分,两台主机的ID要不一样
slave的 [mysqld] server-id=3
然后重启服务 第二步:授权
MySQL报错:The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement
The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement
解决办法:
mysql> set global read_only=0;
(关掉新主库的只读属性)flush privileges;
set global read_only=1;(读写属相)
flush privileges;
master上授权,super和replication slave都是复制要用的权限 mysql> grant super,replication slave on *.* to 'jerry'@'10.1.1.7' identified by '123'; mysql> flush privileges;
mysql> show master status; --只有打开二进制日志,这句命令才有结果,表示当前数据库的二进制日志写到什么位置 +------------------+----------+--------------+------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | +------------------+----------+--------------+------------------+ | mysql-bin.000001 | 563 | | | +------------------+----------+--------------+------------------+
slave端的配置 mysql> slave stop; --如果没有启过slave,这一步也是非必要的 Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> show warnings;
+-------+------+--------------------------------+ | Level | Code | Message | +-------+------+--------------------------------+ | Note | 1255 | Slave already has been stopped | +-------+------+--------------------------------+//此处为从的设置:需要master先授权 mysql> change master to -> master_user='jerry', -> master_password='123', -> master_host='10.1.1.6', --主的IP -> master_port=3306, --端口,如果为3307就要换成3307 -> master_log_file='mysql-bin.000001', --主上面查到的文件名 -> master_log_pos=563; --主上面查到的位置号 change master to master_user='jerry',master_password='123',master_host='10.1.1.6',master_port=3306,master_log_file='mysql-bin.000001',master_log_pos=563; mysql> start slave; Query OK, 0 rows affected (0.00 sec)
mysql> show slave status\G *************************** 1. row *************************** Slave_IO_State: Waiting for master to send event Master_Host: 10.1.1.6 Master_User: li Master_Port: 3306 Connect_Retry: 60 Master_Log_File: mysql-bin.000001 Read_Master_Log_Pos: 563 Relay_Log_File: mysql55-relay-bin.000002 Relay_Log_Pos: 253 Relay_Master_Log_File: mysql-bin.000001 Slave_IO_Running: Yes Slave_SQL_Running: Yes --这里两个YES,表示两个线程OK Replicate_Do_DB: Replicate_Ignore_DB: Replicate_Do_Table: Replicate_Ignore_Table: Replicate_Wild_Do_Table: Replicate_Wild_Ignore_Table: Last_Errno: 0 Last_Error: Skip_Counter: 0 Exec_Master_Log_Pos: 563 Relay_Log_Space: 411 Until_Condition: None Until_Log_File: Until_Log_Pos: 0 Master_SSL_Allowed: No Master_SSL_CA_File: Master_SSL_CA_Path: Master_SSL_Cert: Master_SSL_Cipher: Master_SSL_Key: Seconds_Behind_Master: 0 Master_SSL_Verify_Server_Cert: No Last_IO_Errno: 0 Last_IO_Error: Last_SQL_Errno: 0 Last_SQL_Error: Replicate_Ignore_Server_Ids: Master_Server_Id: 2 1 row in set (0.00 sec)
...................................
***** Slave_IO_Running 为NO,多为授权或者防火墙设置的问题。此处一般为SQL连接问题所至 ================================= 以上为一主一从的设置方法,如果要设置双主,就是所主从的关系变下,更新再设置一遍就是又主 注意点: 1. 授权记得要清下权限 flush privileags; 2. 记得防火墙的设置,主从服务器要PING得通 3. selinux (这个,我经常会忘记这块的设置) =================================