MySQL is the preferred redundancy solution for lightweight database MySQL. The following describes how to configure the system yum in the configuration process of MySQL asynchronous master-slave replication. Here, the installation process of the source code package is introduced as an example! Also do not introduce the yum configuration process, from the installation of mysql is recommended to read: Ubuntu Nginx load Implementation of High Performance WEB Server 5 --- MySQL master synchronization http://www.linuxidc.com/Linux/2
MySQL is the first choice for MySQL redundancy solutions for lightweight databases.
The following is the configuration process of MySQL's asynchronous master-slave replication.
First configure the system yum. Here we will introduce the installation process of the source code package!
The yum configuration process is no longer introduced, starting from mysql installation.
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
Two hosts are used for installation.
Master: 192.168.0.111
Slave: 192.168.0.222
Install MySQL (both master and slave nodes are installed)
Yum-y install mysql-server
Create a mysql data directory (two nodes)
Mkdir/opt/mysql_data & chown-R mysql. mysql/opt/mysql_data & chmod 766/opt/mysql_data
Configure mysqld (master node)
Edit/etc/my. cnf as follows. Start mysql first (two nodes ):
[Mysqld]
Character-set-server = utf8
Datadir =/opt/mysql_data
Socket =/tmp/mysql. sock
User = mysql
Symbolic-links = 0
[Mysqld_safe]
Log-error =/var/log/mysqld. log
Pid-file =/var/run/mysqld. pid
Start mysqld:
Service mysqld start & chkconfig -- level 35 mysqld on
**************************************** ********
Note: Here, master-slave replication is used as the topic, and iptables is not discussed.
And SELinux, so disable SELinux and iptables beforehand.
Otherwise, mysqld cannot start.
**************************************** ********
Create the database to be synchronized and the user to be synchronized (on the master node)
Mysql> grant replication slave, reload, super on *. * to cai@192.168.0.222 identified by 'cai '; // create a cai user
Query OK, 0 rows affected (0.00 sec)
Mysql> grant all privileges on *. * to cai@192.168.0.222 identified by 'cai ';
Query OK, 0 rows affected (0.00 sec)
Mysql> create database caidb; // create the database to be synchronized
Query OK, 1 row affected (0.00 sec)
Mysql> show databases; select user, host from mysql. user; // view the created database and user information
+ -------------------- +
| Database |
+ -------------------- +
| Information_schema |
| Caidb |
| Mysql |
| Test |
+ -------------------- +
4 rows in set (0.01 sec)
+ ------ + --------------- +
| User | host |
+ ------ + --------------- +
| Root | 127.0.0.1 |
| Cai | 192.168.0.222 |
| Localhost |
| Root | localhost |
| Master |
| Root | master |
+ ------ + --------------- +
6 rows in set (0.00 sec)
Connect to the master node on the slave node to test the network and user availability:
[Root @ slave ~] # Mysql-ucai-pcai-h 192.168.0.111-e "select user, host from mysql. user; show databases;" // Use cai to log on to the remote database 192.168.0.111 and execute the SQL "show databases"
+ ------ + --------------- +
| User | host |
+ ------ + --------------- +
| Root | 127.0.0.1 |
| Cai | 192.168.0.222 |
| Localhost |
| Root | localhost |
| Master |
| Root | master |
+ ------ + --------------- +
+ -------------------- +
| Database |
+ -------------------- +
| Information_schema |
| Caidb |
| Mysql |
| Test |
+ -------------------- +
Create tables and simulate data in the database to be synchronized (on the master)
Mysql> create table 'caitable' ('id' int (5) not null auto_increment, 'name' varchar (32) not null, 'Password' char (32) not null, primary key ('id'); // create a table
Insert the simulated data using the script:
[Root @ master ~] # Cat ist. sh
#! /Bin/bash
For (I = 1; I <= 10; I ++) // Insert 10 data records cyclically
Do
Mysql-uroot-e "insert into caidb. caitable (id, name, password) value ('$ I', 'user $ I ', md5 ('usercai $ I '));"
Done
Mysql-uroot-e "select * from caidb. caitable;" // query inserted data
Next please see page 2nd: http://www.linuxidc.com/Linux/2013-08/88518p2.htm