1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > 如何设置MySQL的主从复制

如何设置MySQL的主从复制

时间:2018-09-13 01:40:14

相关推荐

如何设置MySQL的主从复制

数据库|mysql教程

MySQL

数据库-mysql教程

本篇文章给大家介绍的是关于在MySQL服务器之间设置主从复制,下面我们来看具体内容。

php模块源码,deb下载位置ubuntu,爬虫的单词缩写,golbal php,网站名片seolzw

nitc源码下载,vscode如何添加背景,进入ubuntu蓝屏,Tomcat的常用版本,rsshub爬虫,编译安装php5.4,西安英文seo主管招聘,行云海cms 网站描述,手机html5九宫格模板lzw

设置细节:

天网防火墙程序源码,ubuntu如何安装dns,tomcat域账号密码,怎样爬虫购物,php rtmp直播,秒收录怎么做霸屏seo 优化lzw

主服务器:192.168.1.10

从服务器:192.168.1.20

数据库:mydb

1.设置MySQL主服务器

在主服务器上创建一个具有REPLICATION SLAVE权限的mysql帐户,复制客户端将连接到master。

mysql> GRANT REPLICATION SLAVE ON *.* TO epl_user@192.168.1.20 IDENTIFIED BY secretpassword;mysql> FLUSH PRIVILEGES;

在所有表上都有block write语句,因此不要在备份后进行更改。

mysql> use mydb;mysql> FLUSH TABLES WITH READ LOCK;mysql> exit;

编辑mysql配置文件并在[mysqld]部分下添加以下代码。

# vim /etc/f

[mysqld]log-bin=mysql-binbinlog-do-db=mydbserver-id=1innodb_flush_log_at_trx_commit=1sync_binlog=1

重新启动master mysql服务器以使更改生效。

# service mysqld restart

使用以下命令检查当前二进制日志文件名(File)和当前偏移量(Position)值。

mysql > SHOW MASTER STATUS;+------------------+----------+--------------+------------------+| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |+------------------+----------+--------------+------------------+| mysql-bin.000002 |107 | mydb | |+------------------+----------+--------------+------------------+

以上输出显示当前二进制文件使用的是mysql-bin.000002,偏移值为107。记下这些值以在从属服务器上使用。

备份数据库并将其复制到slave mysql server。

# mysqldump -u root -p mydb > mydb.sql# scp mydb.sql 192.168.1.20:/opt/

完成备份后,从表中删除READ LOCK,以便进行更改。

mysql> UNLOCK TABLES;

2.设置MySQL Slave Server

编辑salve mysql配置文件并在[mysqld]部分下添加以下值。

# vim /etc/f

[mysqld]server-id=2replicate-do-db=mydb

server-id始终为非零数值。这些值永远不会与其他主服务器和从服务器相似。

重启mysql slave server,如果你已经配置了复制,请在启动时使用-skip-slave-start,不要立即连接到主服务器。

# /etc/init.d/mysqld restart

使用以下命令在从属服务器上设置选项值。

mysql> CHANGE MASTER TO MASTER_HOST=192.168.1.10, -> MASTER_USER= epl_user, -> MASTER_PASSWORD=secretpassword, -> MASTER_LOG_FILE=mysql-bin.000002, -> MASTER_LOG_POS=107;

最后启动从属线程

mysql> SLAVE START;

检查从服务器的状态。

mysql> show slave status G

*************************** 1. row ***************************Slave_IO_State: Master_Host: 192.168.1.15 Master_User: repl_user Master_Port: 3306Connect_Retry: 60 Master_Log_File: mysql-bin.000002Read_Master_Log_Pos: 107Relay_Log_File: mysqld-relay-bin.000001Relay_Log_Pos: 4 Relay_Master_Log_File: mysql-bin.000002 Slave_IO_Running: No Slave_SQL_Running: No Replicate_Do_DB: mydbReplicate_Ignore_DB: Replicate_Do_Table: Replicate_Ignore_Table:Replicate_Wild_Do_Table: Replicate_Wild_Ignore_Table: Last_Errno: 0 Last_Error: Skip_Counter: 0Exec_Master_Log_Pos: 107 Relay_Log_Space: 107 Until_Condition: NoneUntil_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: NULLMaster_SSL_Verify_Server_Cert: NoLast_IO_Errno: 0Last_IO_Error:Last_SQL_Errno: 0Last_SQL_Error: Replicate_Ignore_Server_Ids: Master_Server_Id: 11 row in set (0.00 sec)mysql>

MySQL主从复制已在你的系统和工作模式下成功配置。

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。