MySQL's master-slave replication environment

Source: Internet
Author: User

Note Version impact:
To realize the hot standby of a dual machine first, we need to know the version of the master-slave database server. First of all, the MySQL version is more than 3.2, there is a basic principle is to make
The database version from the database can be higher than the version of the primary server database, but not lower than the database version of the primary server

Lab Environment:
Master:192.168.0.101
slave:192.168.0.113

The package is installed via RPM;
The installation version is rhel5.5;

Vim/etc/yum.repos/yum.repo
[Base] #名字可以随便设置
Name=name #第二个name也是可以随便设置的
Baseurl=file:///mnt/server # BaseURL is the directory of files you mount;
Gpgcheck=0 #不检查密钥

Install the MySQL service via Yum just install these two and you can have MySQL Mysql-server

Yum-y install MySQL Mysql-server


#mysql. i686 0:5.1.52-1.el6_0.1 mysql-server.i686 0:5.1.52-1.el6_0.1

#Complete!

[Email protected] ~]# VIM/ETC/MY.CNF

Server-id=1
Log-bin=logbin



########### #注意不要把server-id added to [Mysqld_safe] ######

When you are done, quit restarting service mysqld restart

#登录到MySQL里 Mysql-u Root

[Email protected] ~]# mysql-u root


Mysql> Show master status;
+---------------+----------+--------------+------------------+
| File | Position | binlog_do_db | binlog_ignore_db |
+---------------+----------+--------------+------------------+
|     logbin.000003 |              98|                  | |
+---------------+----------+--------------+------------------+
1 row in Set (0.00 sec)

Mysql>
Check to see if there is a binary file in the logbin.000001

Mysql> Grant Replication Slave,reload,super on * * to [E- Mail protected] identified by ' 123123 ';
Query OK, 0 rows Affected (0.00 sec)

Authorize the appropriate library permissions to the Slave


Mysql> FLUSH TABLES with READ LOCK;

# Lock Table Lie

Quit # quit MySQL

Slave set:

Configuring the Slave file
Vim/etc/my.cnf

server-id=2
master-host=192.168.0.113
Master-user=slave
Master-password=123123


Directly overwrite the file contents of the original file can also be

Service mysqld Restart # restart under slave services

Link under master server
[Email protected] ~]# mysql-u slave-p123123-h 192.168.0.113 #ip is master IP address

Make sure that slave can link master

ERROR 2003 (HY000): Can ' t connect to MySQL server on ' 192.168.0.113 ' (113)
Shut down the firewall when #出现这种错误. Service iptables stop is OK

Mysql-u root-p


Change MASTER to
->master_host= ' 192.168.1.128 ',
->master_user= ' slave ',
->master_password= ' 123123 ',
->master_log_file= ' logbin.000003 ', # This file can be copied from the master server ls/var/lib/mysql/
->master_log_pos=98;

mysql> start slave;

#在主服务器上创建库文件
mysql> CREATE DATABASE BBS;
Query OK, 1 row Affected (0.00 sec) # Create a library look at Sync No
Mysql>show databases;
+--------------------+
| Database |
+--------------------+
| Information_schema |
| BBS |
| MySQL |
| Test |
+--------------------+
4 rows in Set (0.00 sec)
#在从服务器上查看
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| Information_schema |
| BBS |
| MySQL |
| Test |
+--------------------+
4 rows in Set (0.00 sec)


Finished. master-slave replication synchronization

This article from "Linux.yang" blog, declined reprint!

MySQL's master-slave replication environment

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.