Mysql high availability (master-slave), mysql available master-slave
Basic server environment:
Two centos6.4, iptables diabled, and selinux disabled
Two hosts Parsing
# Yum install mysql-y // This installation does not affect installation, but you must install the mysqldump command to avoid any problems.
Install mysql (two identical operations ):
Mysql users and groups
# Groupadd mysql
# Useradd-r-g mysql
Various mysql usage Directories
Data DIRECTORY mount point:/data
Database base Directory:/usr/local/mysql
Database Configuration File Location:/etc/my. cnf
Database data Directory:/data/mysql
Innodb data and innodb log directory:/data/mysql
# Mkdir/data/mysql
# Mkdir/usr/local/mysql
Mysql Decompression
# Tar zxvf/home/mysql-5.5.9.tar.gz-C/data
Mysql Compilation
# Cmake .\
>-DCMAKE_INSTALL_PREFIX =/usr/local/mysql /\
>-DMYSQL_DATADIR =/data/mysql /\
>-DWITH_INNOBASE_STORAGE_ENGINE = 1 \
>-DENABLED_LOCAL_INFILE = 1 \
>-DMYSQL_TCP_PORT = 3306 \
>-DEXTRA_CHARSETS = all \
>-DDEFAULT_CHARSET = utf8 \
>-DDEFAULT_COLLATION = utf8-general_ci \
>-DWITH_DEBUG =
Enter
# Make & make install
Mysql configuration file
# Cd/usr/local/mysql
# Cp/data/mysql-5.5.9/support-files/my-medium.cnf/etc/my. cnf
Mysql Startup Script
# Cp/data/mysql-5.5.9/support-files/mysql. server/etc/init. d/mysqld
# Chmod + x/etc/init. d/mysqld
Initialize Database
# Cd/usr/local/mysql
#./Usr/local/mysql/scripts/mysql_install_db -- user = mysql -- ldata =/data/mysql
Start mysql
#/Etc/init. d/mysqld start
Set root Password
# Mysql-uroot-p // you can press enter if you have a password.
Mysql> update mysql. user set password = password ("password") where user = "root ";
// Mysq indicates the Database Name and user indicates the table name.
Mysql> flush privileges;
Master/Slave Configuration:
Master Server Configuration
Mysql> grant replication slave on *. * to 'mysql' @ 'slave Server IP 'identified by 'Password ';
Mysql> show master status;
# Vim/etc/my. cnf // you need to change it to two places.
Log-bin = mysql-bin // This is usually the display, log-bin must be set to mysql-bin, this enabling mysql will generate many files similar to the mysql-bin.00001, these files are mainly used to record data recovery and synchronize data between master and slave servers. If high availability is not enabled, this option can be disabled to avoid affecting system performance.
Server-id = 144 // server-id is used to identify the server thread. For example, when mysql is highly available, the master thread and slave thread use this label. The id of the master and slave must be different (otherwise, your I/O process will fail to communicate). Even if one master node has N slave nodes, the IDs of the N slave nodes must be different.
Slave server settings
# Vim/etc/my. cnf // you need to change it to two places.
Log-bin = mysql-bin
Servers-id = 145
Mysql> change master to master_host = 'master server ip', master_user = 'mysql', master_password = 'Password ';
Mysql> start slave
Mysql> show slave status \ G
I/OProcess andSQLAll threads must communicate successfully !!!! The master and slave nodes can be synchronized !!!