不导出指定表,如果有多个表不需要导出,需要使用多个--ignore-table 参数
--master-data=[1|2] 如果设置--master-data=1将会显示如下信息:
--
-- Position to start replication or point-in-time recovery from
--
CHANGE MASTER TO MASTER_LOG_FILE='mysql-bin.000003', MASTER_LOG_POS=3018292;
--
这样如果设置SLAVE的时候就不需要再单独指定MASTER_LOG_FILE和MASTER_LOG_POS
如何设置--master-data=2,CHANGE MASTER TO 这一行将被注释掉,当设置SLAVE的同步需要按照这里的提示设置MASTER_LOG_FILE和MASTER_LOG_POS
设置--master-data参数,配合--single-transaction参数可以不锁表。
--single-transaction 保证备份数据的一致性,目前支持InnoDB
--quick Don't buffer query, dump directly to stdout.
-R 导出函数和存储过程
--event Dump events
2.导入数据到UDB
如果数据量太大,导入的时间会很长,可以使用screen开一个窗口,可以随时查看进度
mysql -h10.4.21.160 -uroot -p
mysql> source mysql_data20150203.sql
这里导入数据的时候有几个小故障,由于UDB默认设置为Master,开启了binlog,所以导入数据的时候UDB的binlog增长太快,把500G磁盘写满后,导入失败。
可以设置导入的时候不写入binlog
SET sql_log_bin=0
由于使用mysqldump导出的时候使用了 -A 参数,没有过滤掉mysql库,所以如果Uhost的MySQL里面没有设置除了root账号外具有合适权限登录的账号,那么在以下设置Slave的时候就会出错。
这种情况下,可以使用--skip-grant-tables参数重新启动UDB,然后再重新设置root账号密码。
3.设置UDB为MySQL Slave,从Uhost上的MySQL同步数据
CHANGE MASTER TO MASTER_HOST='10.4.3.149',MASTER_PORT=3306,MASTER_USER='repl_user',MASTER_PASSWORD='xyzzy',MASTER_LOG_FILE='mysql-bin.000003', MASTER_LOG_POS=3018292;
同步过程中,查看Slave的状态信息,主要观察以下几个参数
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Seconds_Behind_Master: 0
在同步过程中,Seconds_Behind_Master 数值会越来越小,如果同步出错,会有报错信息显示
mysql> show slave status\G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 10.4.3.149
Master_User: repl_user
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000005
Read_Master_Log_Pos: 925459151
Relay_Log_File: mysql-relay.000012
Relay_Log_Pos: 294731160
Relay_Master_Log_File: mysql-bin.000005
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
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: 925459151
Relay_Log_Space: 294731312
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)
mysql>
4.停掉Uhost上的MySQL
5.更改程序里面的MySQL连接信息
6.取消UDB的Slave设置
先使用STOP SLAVE;命令停掉UDB上的SLAVE设置mysql> stop slave;
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> show slave status\G
*************************** 1. row ***************************
Slave_IO_State:
Master_Host: 10.4.3.149
Master_User: repl_user
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000006
Read_Master_Log_Pos: 351201559
Relay_Log_File: mysql-relay.000016
Relay_Log_Pos: 15191656
Relay_Master_Log_File: mysql-bin.000006
Slave_IO_Running: No
Slave_SQL_Running: No
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: 351201559
Relay_Log_Space: 15191808
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: NULL
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 2003
Last_IO_Error: error reconnecting to master 'repl_user@10.4.3.149:3306' - retry-time: 60 retries: 86400
Last_SQL_Errno: 0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 1
1 row in set (0.00 sec)
mysql>mysql> reset slave all;
Query OK, 0 rows affected (0.02 sec)
mysql> show slave status\G
Empty set (0.00 sec)
然后使用RESET SLAVE ALL;命令清楚UDB上的SLAVE设置。
本文原创发布php中文网,转载请注明出处,感谢您的尊重!
相关文章
相关视频
网友评论
文明上网理性发言,请遵守 新闻评论服务协议我要评论
立即提交
专题推荐独孤九贱-php全栈开发教程
全栈 100W+
主讲:Peter-Zhu 轻松幽默、简短易学,非常适合PHP学习入门
玉女心经-web前端开发教程
入门 50W+
主讲:灭绝师太 由浅入深、明快简洁,非常适合前端学习入门
天龙八部-实战开发教程
实战 80W+
主讲:西门大官人 思路清晰、严谨规范,适合有一定web编程基础学习
php中文网:公益在线php培训,帮助PHP学习者快速成长!
Copyright 2014-2020 https://www.php.cn/ All Rights Reserved | 苏ICP备2020058653号-1