In Linux, MySQL is configured with master-slave nodes.
Linux: CentOS 6.5
Master1: 192.168.100.204
Master2: 192.168.100.205
Mysql version: mysql-5.6.19
Note: The configuration methods for versions earlier than mysql 5.5 and later are different.
Install the following two nodes:
1: Firewall opens the corresponding port
#/Sbin/iptables-I INPUT-p tcp -- dport 3306-j ACCEPT
#/Etc/rc. d/init. d/iptables save
2: Install related dependency packages
# Yum-y install gcc-c ++ ncurses-devel openssl-devel cmake perl lsof bison
3: delete the mysql
# Rpm-qa | grep mysql
# Rpm-e -- allmatches -- nodeps mysql-libs-5.1.71-1.el6.x86_64
4. Create related directories
# Mkdir/bkjia/soft
# Mkdir-p/bkjia/mysql/data/
5. Create a mysql user
#/Usr/sbin/groupadd mysql
#/Usr/sbin/useradd-s/sbin/nologin-M-g mysql
# Chown-R mysql: mysql/bkjia/mysql/
6. Install mysql
# Cd/bkjia/soft
# Tar-zxvf mysql-5.6.19.tar.gz
# Cd mysql-5.6.19
# Cmake-DCMAKE_INSTALL_PREFIX =/bkjia/server/mysql-DMYSQL_DATADIR =/bkjia/mysql/data-encoding = 1-runtime = 1-runtime = 1-DSYSCONFDIR =/etc/-DWITH_SSL = yes-DDEFAULT_CHARSET = utf8-DDEFAULT_COLLATION = utf8_general_ci-DWITH_READLINE = on
# Make & make install
7. Modify related directory permissions and create a soft connection
# Chmod + w/bkjia/server/mysql
# Chown-R mysql: mysql/bkjia/server/mysql/
# Ln-s/bkjia/server/mysql/lib */usr/lib/
# Ln-s/bkjia/server/mysql/bin/mysql/usr/bin
8. modify the configuration file.
# Cp/bkjia/server/mysql/support-files/my-default.cnf/etc/my. cnf
# Vi/etc/my. cnf
[Mysqld]
Character-set-server = utf8
Default-storage-engine = MyISAM
Basedir =/bkjia/server/mysql
Datadir =/bkjia/mysql/data
Log-error =/bkjia/mysql/mysql_error.log
Pid-file =/bkjia/mysql. pid
Max_allowed_packet = 32 M
Explicit_defaults_for_timestamp = true
9. Install the mysql database.
#/Bkjia/server/mysql/scripts/mysql_install_db -- basedir =/bkjia/server/mysql -- datadir =/bkjia/mysql/data -- user = mysql
10: Set mysql to automatically start the service
# Cp/bkjia/server/mysql/support-files/mysql. server/etc/init. d/mysqld
# Chkconfig -- add mysqld
# Chkconfig -- level 345 mysqld on
11. Modify the mysqld file and start mysql
# Vi/etc/init. d/mysqld
# Modify the following two items in the mysqld File
Basedir =/bkjia/server/mysql
Datadir =/bkjia/mysql/data
# Service mysqld start
12: Create the database to be synchronized
# Mysql-uroot-p
Mysql> create database bkjia;
Mysql> grant all privileges on bkjia. * TO doiido @ "%" identified by 'bkjia123 ';
Mysql> exit
-------------------- The following operations are performed on server master1
Modify configuration file
# Vi/etc/my. cnf
[Mysqld]
# The default value is 1. The master and slave cannot be the same.
Server-id = 1
Log-bin = bin. log
Port = 3306
Binlog-do-db = bkjia
# Databases to be copied
Replicate-do-db = bkjia
Restart mysql
# Service mysqld restart
Create an account for synchronization
# Mysql-uroot-p
Mysql> grant replication slave on *. * to 'dodo '@ '192. 168.100.205' identified by 'jjjjjjj ';
View the File value and record it
Mysql> show master status;
+ ------------------ + ---------- + -------------- + -------------------- + ------------------- +
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+ ------------------ + ---------- + -------------- + -------------------- + ------------------- +
| Bin.000001 | 120 | bkjia |
+ ------------------ + ---------- + -------------- + -------------------- + ------------------- +
Mysql> exit
-------------------- The following operations are performed on server master2
2. modify the configuration file my. cnf on the slave.
# Vi/etc/my. cnf
[Mysqld]
Server-id = 2
Port = 3306
Log-bin = bin. log
Binlog-do-db = bkjia
Replicate-do-db = bkjia
Restart mysql
# Service mysqld restart
Create a database on the slave server
# Mysql-uroot-p
Set 192.168.100.204 as your master server
Mysql> CHANGE MASTER
MASTER_HOST = '1970. 168.100.204 ', MASTER_PORT = 192,
MASTER_USER = 'dodo ',
MASTER_PASSWORD = 'jjjjjjj ',
MASTER_LOG_FILE = 'bin. 000001 ',
MASTER_LOG_POS = 120;
Enable slave Server replication
Mysql> start slave;
Mysql> show slave status \ G;
...................
Slave_IO_Running: Yes
Slave_ SQL _Running: Yes
...................
Note:
# Slave_IO_Running: connects to the master database and reads logs from the master database to the local computer to generate local log files.
# Slave_ SQL _Running: Read the local log file and execute the SQL command in the log.
Both of the above must be yes, and one of them is an error.
Mysql> exit
At this point, the one-way Master/Slave configuration is complete. If you need to be mutually Master/Slave, the configuration is as follows:
-------------------- The following operations are performed on server master2
Create an account for synchronization
# Mysql-uroot-p
Mysql> grant replication slave on *. * to 'dodo '@ '192. 168.100.204' identified by 'jjjjjjj ';
View the File value and record it
Mysql> show master status;
+ ------------------ + ---------- + -------------- + -------------------- + ------------------- +
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+ ------------------ + ---------- + -------------- + -------------------- + ------------------- +
| Bin.000001 | 649 | bkjia |
+ ------------------ + ---------- + -------------- + -------------------- + ------------------- +
1 row in set (0.00 sec)
Mysql> exit
-------------------- The following operations are performed on server master1
Set 192.168.100.205 as your master server
Mysql> CHANGE MASTER
MASTER_HOST = '1970. 168.100.205 ',
MASTER_PORT = 3306,
MASTER_USER = 'dodo ',
MASTER_PASSWORD = 'jjjjjjj ',
MASTER_LOG_FILE = 'bin. 000001 ',
MASTER_LOG_POS = 649;
Enable slave Server replication
Mysql> start slave;
Mysql> show slave status \ G;
...................
Slave_IO_Running: Yes
Slave_ SQL _Running: Yes
...................
Both of the above must be yes, and one of them is an error.
Mysql> exit
The master-slave configuration is complete.
-------------------------------------- Split line --------------------------------------
Install MySQL in Ubuntu 14.04
MySQL authoritative guide (original book version 2nd) Clear Chinese scan PDF
Ubuntu 14.04 LTS install LNMP Nginx \ PHP5 (PHP-FPM) \ MySQL
Build a MySQL Master/Slave server in Ubuntu 14.04
Build a highly available distributed MySQL cluster using Ubuntu 12.04 LTS
Install MySQL5.6 and Python-MySQLdb in the source code of Ubuntu 12.04
MySQL-5.5.38 universal binary Installation
-------------------------------------- Split line --------------------------------------
This article permanently updates the link address: