Tutorial start: 1. Install MySQL instructions: perform the following operations on the two MySQL servers 192.168.21.169 and 192.168.21.168 respectively, install MySQL5.5.22 and configure the MySQL master server (192.168.21.169) mysql-uroot-p # Enter MySQL console createdatabaseosyunweidb; # create database osyunweidbinsertintomy
Tutorial start:
1. Install MySQL
Note: perform the following operations on the two MySQL servers 192.168.21.169 and 192.168.21.168 respectively to install MySQL 5.5.22.
2. Configure the MySQL master server (192.168.21.169)
Mysql-uroot-p # enter the MySQL Console
Create database osyunweidb; # create database osyunweidb
Insert into mysql. user (Host, User, Password) values ('localhost', 'osyunweiuser', password ('20140901'); # create user osyunweiuser
# Create a MySQL master-slave database to synchronize user osyunweidbbak password 123456
Flush privileges; # refresh the System Authorization Table
# Authorize the user osyunweidbbak to only access the database above the master server 192.168.21.169 from the IP address 192.168.21.168, and only have the database backup permission
Grant replication slave on *. * to 'oss idbbak' @ '192. 168.21.168 'identified by '20140901' with grant option;
3. Import the database osyunweidb in MySQL master server 192.168.21.169 to MySQL slave server 192.168.21.168.
1. Export the database osyunweidb
Mysqldump-u root-p osyunweidb>/home/osyunweidbbak. SQL # export the database osyunweidb to/home/osyunweidbbak. SQL on the MySQL master server
Note: Before exporting data, you can log on to the MySQL console and execute the following command:
Flush tables with read lock; # Database read-only lock command to prevent data writing during Database Export
Unlock tables; # unlock
2. Import the database to the MySQL slave server
Mysql-u root-p # Go To The MySQL console of the slave server
Create database osyunweidb; # create a database
Use osyunweidb # enter the database
Source/home/osyunweidbbak. SQL # import the backup file to the database
Mysql-u osyunweidbbak-h 192.168.21.169-p # test logon to the master server on the slave server
4. Configure the my. cnf file of the MySQL master server
Vi/etc/my. cnf # edit the configuration file and add the following content in the [mysqld] section.
Server-id = 1 # Set the server id. If it is set to 1, it indicates the master server. Note: if this line already exists in the original configuration file, you do not need to add it again.
Log_bin = mysql-bin # Start the MySQ binary log system. Note: if this line already exists in the original configuration file, you do not need to add it again.
Binlog-do-db = osyunweidb # Name of the database to be synchronized. If there are multiple databases, repeat this parameter. Each database has one row.
Binlog-ignore-db = mysql # Do not synchronize the mysql System Database
Service mysqld restart # restart MySQL
Mysql-u root-p # enter the mysql Console
Show master status; view the master server. The following similar information appears:
+ ------------------ + ---------- + -------------- + ------------------ +
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+ ------------------ + ---------- + -------------- + ------------------ +
| Mysql-bin.000019 | 7131 | osyunweidb | mysql |
+ ------------------ + ---------- + -------------- + ------------------ +
1 row in set (0.00 sec)
Note: Remember the File value here:Mysql-bin.000019And Position values:7131, Which will be used later.
For more details, refer to the highlights on the next page.: Http://www.linuxidc.com/Linux/2013-10/91117p2.htm
Recommended reading:
Ubuntu Nginx load Implementation of High Performance WEB Server 5 --- MySQL master synchronization http://www.linuxidc.com/Linux/2012-06/61687p5.htm
Production Environment MySQL master synchronization primary key conflict processing http://www.linuxidc.com/Linux/2013-07/86890.htm
MySQL Master/Slave failure error Got fatal error 1236 http://www.linuxidc.com/Linux/2012-02/54729.htm
MySQL master-slave replication, http://www.linuxidc.com/Linux/2013-03/81913.htm on a single server
Install MySQL dual-instance compilation and configure master-slave replication http://www.linuxidc.com/Linux/2011-12/48873.htm under Ubuntu