《Mysql入门MySQL 主从同步部分数据表》要点:
本文介绍了Mysql入门MySQL 主从同步部分数据表,希望对您有用。如果有疑问,可以联系我们。
MYSQL入门主服务器IP:192.168.1.100 从服务器IP:192.168.1.101
MYSQL入门在配置MySQL主从同步的时候需要保证一下几点:
MYSQL入门1、更改主服务器MySQL配置文件,/etc/my.cnf
,检查二进制日志log-bin是否开启了,把server-id设置为1
MYSQL入门
[mysqld]
log-bin=mysql-bin
binlog_format=mixed
server-id = 1
MYSQL入门2、创建一个从服务器链接主服务器的帐号 (1)、在命令行下登录mysql:
MYSQL入门
# mysql -uroot -p
MYSQL入门(2)、首先创建一个名为:slave_user,密码为:987654321的帐号
MYSQL入门
mysql> grant replication slave on *.* to 'slave_user'@‘192.168.1.%’ identified by '987654321';
Query OK, 0 rows affected (0.52 sec)
MYSQL入门(3)、查看二进制日志的信息,记录下当前的二进制文件名称和位置:
MYSQL入门
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 508296
Server version: 5.5.48-log Source distribution
Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show master status;
+------------------+-----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+-----------+--------------+------------------+
| mysql-bin.000019 | 864074260 | | |
+------------------+-----------+--------------+------------------+
1 row in set (0.00 sec)
MYSQL入门(4)、对数据库进行锁表操作,防止我们在导出数据的时候还有数据写入,然后导出我们需要的数据表,再把数据表导入到从服务器去
MYSQL入门
mysql> unlock tables;
mysql> Ctrl-C -- exit!
Aborted
[root@192 ~]# mysqldump -uroot -p******** erp claim_staff>claim_staff.sql;
MYSQL入门1、更改从服务器MySQL配置文件,/etc/my.cnf
,检查二进制日志log-bin是否开启了,把server-id设置为为一个的一个id(推荐设置成服务器的最后一组数字)
MYSQL入门
[mysqld]
server-id = 101
#我们再改变一些二进制日志文件的名称(可选)
log-bin=mysql-relay-bin
replicate-do-table=erp.claim_staff
2、配置同步参数: 参数说明: | 参数 | 说明 |
---|---|---|
MASTER_HOST | 主服务器IP地址 | |
MASTER_PORT | 主服务器端口 | |
MASTER_USER | 主服务器用户名 | |
MASTER_PASSWORD | 主服务器密码 | |
MASTER_LOG_FILE | 主服务器当前binlog文件(前面我们获取到“mysql-bin.000019”) | |
MASTER_LOG_POS | 主服务器当前binlog文件的位置(就是我们前面获取到的Position的值:864074260) |
MYSQL入门
mysql> CHANGE MASTER TO MASTER_HOST='192.168.1.249',MASTER_USER='slave_user',MASTER_PASSWORD='987654321',MASTER_LOG_FILE='mysql-bin.000019',MASTER_LOG_POS=865765533;
Query OK, 0 rows affected (0.11 sec)
MYSQL入门3、启动同步进程,然后检查状态
MYSQL入门
#启动同步进程
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: 192.168.1.100
Master_User: slave_user
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000019
Read_Master_Log_Pos: 873059878
Relay_Log_File: 192-relay-bin.000002
Relay_Log_Pos: 7294598
Relay_Master_Log_File: mysql-bin.000019
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table: erp.claim_staff
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 873059878
Relay_Log_Space: 7294752
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: 1
1 row in set (0.00 sec)
ERROR:
No query specified
MYSQL入门这么多信息中,我们只需要看2项,只要为YES即可,分别是:
MYSQL入门
Slave_IO_Running: Yes # 去主库读二进制日志,然后保存到从库去
Slave_SQL_Running: Yes # 将中继日志转换成为SQL语句执行
MYSQL入门4、到这里,主从同步指定的表也完成了.
转载请注明本页网址:
http://www.vephp.com/jiaocheng/5584.html