This article introduces to you about setting up master-slave replication between MySQL servers. Let’s take a look at the specific content.
Setting details:
Master server: 192.168.1.10
Slave server: 192.168.1.20
Database: mydb
1. Set up the MySQL main server
Create a server with REPLICATION SLAVE permissions on the main server mysql account, the replication client will connect to the master.
mysql> GRANT REPLICATION SLAVE ON *.* TO 'repl_user'@'192.168.1.20' IDENTIFIED BY 'secretpassword'; mysql> FLUSH PRIVILEGES;
Have block write statements on all tables, so do not make changes after backup.
mysql> use mydb; mysql> FLUSH TABLES WITH READ LOCK; mysql> exit;
Edit the mysql configuration file and add the following code under the [mysqld] section.
# vim /etc/my.cnf
[mysqld] log-bin=mysql-bin binlog-do-db=mydb server-id=1 innodb_flush_log_at_trx_commit=1 sync_binlog=1
Restart the master mysql server for the changes to take effect.
# service mysqld restart
Use the following command to check the current binary log file name (File) and current offset (Position) value.
mysql > SHOW MASTER STATUS; +------------------+----------+--------------+------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | +------------------+----------+--------------+------------------+ | mysql-bin.000002 | 107 | mydb | | +------------------+----------+--------------+------------------+
The above output shows that the current binary file is using mysql-bin.000002 with an offset value of 107. Note these values for use on the slave server.
Back up the database and copy it to slave mysql server.
# mysqldump -u root -p mydb > mydb.sql # scp mydb.sql 192.168.1.20:/opt/
After completing the backup, remove the READ LOCK from the table so that changes can be made.
mysql> UNLOCK TABLES;
2. Set up MySQL Slave Server
Edit the salve mysql configuration file and add the following values under the [mysqld] section.
# vim /etc/my.cnf
[mysqld] server-id=2 replicate-do-db=mydb
server-id is always a non-zero value. These values will never be similar to other masters and slaves.
Restart the mysql slave server. If you have configured replication, please use -skip-slave-start when starting. Do not connect to the master server immediately.
# /etc/init.d/mysqld restart
Use the following commands to set option values on the slave server.
mysql> CHANGE MASTER TO MASTER_HOST='192.168.1.10', -> MASTER_USER='repl_user', -> MASTER_PASSWORD='secretpassword', -> MASTER_LOG_FILE='mysql-bin.000002', -> MASTER_LOG_POS=107;
Finally start the slave thread
mysql> SLAVE START;
Check the status of the slave server.
mysql> show slave status G
*************************** 1. row *************************** Slave_IO_State: Master_Host: 192.168.1.15 Master_User: repl_user Master_Port: 3306 Connect_Retry: 60 Master_Log_File: mysql-bin.000002 Read_Master_Log_Pos: 107 Relay_Log_File: mysqld-relay-bin.000001 Relay_Log_Pos: 4 Relay_Master_Log_File: mysql-bin.000002 Slave_IO_Running: No Slave_SQL_Running: No Replicate_Do_DB: mydb 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: 107 Relay_Log_Space: 107 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: 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>
MySQL master-slave replication has been successfully configured on your system and work mode.
The above is the detailed content of How to set up MySQL master-slave replication. For more information, please follow other related articles on the PHP Chinese website!

本篇文章给大家带来了关于mysql的相关知识,其中主要介绍了关于架构原理的相关内容,MySQL Server架构自顶向下大致可以分网络连接层、服务层、存储引擎层和系统文件层,下面一起来看一下,希望对大家有帮助。

在mysql中,可以利用char()和REPLACE()函数来替换换行符;REPLACE()函数可以用新字符串替换列中的换行符,而换行符可使用“char(13)”来表示,语法为“replace(字段名,char(13),'新字符串') ”。

方法:1、利用right函数,语法为“update 表名 set 指定字段 = right(指定字段, length(指定字段)-1)...”;2、利用substring函数,语法为“select substring(指定字段,2)..”。

mysql的msi与zip版本的区别:1、zip包含的安装程序是一种主动安装,而msi包含的是被installer所用的安装文件以提交请求的方式安装;2、zip是一种数据压缩和文档存储的文件格式,msi是微软格式的安装包。

转换方法:1、利用cast函数,语法“select * from 表名 order by cast(字段名 as SIGNED)”;2、利用“select * from 表名 order by CONVERT(字段名,SIGNED)”语句。

本篇文章给大家带来了关于mysql的相关知识,其中主要介绍了关于MySQL复制技术的相关问题,包括了异步复制、半同步复制等等内容,下面一起来看一下,希望对大家有帮助。

本篇文章给大家带来了关于mysql的相关知识,其中主要介绍了mysql高级篇的一些问题,包括了索引是什么、索引底层实现等等问题,下面一起来看一下,希望对大家有帮助。

在mysql中,可以利用REGEXP运算符判断数据是否是数字类型,语法为“String REGEXP '[^0-9.]'”;该运算符是正则表达式的缩写,若数据字符中含有数字时,返回的结果是true,反之返回的结果是false。


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

SublimeText3 Linux new version
SublimeText3 Linux latest version

Notepad++7.3.1
Easy-to-use and free code editor
