Normal user MySQL 5.6.13 Master-Slave

Source: Internet
Author: User
Tags mysql query

master:192.168.209.19

slave:192.168.209.20

MySQL version: mysql5.6.13

1. Create a normal user as root, such as MySQL, and create the MySQL installation directory:

# useradd MySQL

# passwd MySQL

# Mkdir/mysql

# chown Mysql:mysql/mysql

To install a dependency package:

Yum-y install gcc gcc-c++ autoconf automake zlib* fiex* libxml* ncurses-devel libmcrypt* libtool-ltdl-devel* make CMake

2. Download the full development version of MySQL5.6.13 and copy it to the/mysql directory.

Files: mysql-5.6.13.tar.gz

3. Unpack MySQL with MySQL user and change the directory after the MySQL unpacking to/mysql/:

# Su-mysql

$ cd

$ MV Mysql-5.6.13.tar.gz/mysql

$ tar xvzf mysql-5.6.13.tar.gz

4. Configure MySQL:

$ cd/mysql/5.6.13

$cmake-dcmake_install_prefix=/mysql/mysql-5.6

$make

$make Install

$CD/mysql/mysql-5.6/scripts

$./mysql_install_db--user=mysql--basedir=/mysql/mysql-5.6--datadir=/mysql/mysql-5.6/data

#cp/mysql/mysql-5.6/support-files/mysql.server/etc/init.d/mysql

#cp/mysql/mysql-5.6/support-files/my-default.cnf/etc/my.cnf

Start MySQL

$/mysql/mysql-5.6/support-files/mysql.server start

Error Resolution:

[ERROR] Fatal Error:can ' t open and Lock Privilege tables:table ' mysql.user ' doesn ' t exist

Initialize the database on OK, i.e.:./mysql_install_db--user=mysql--basedir=/mysql/mysql-5.6--datadir=/mysql/mysql-5.6/data

5. Configure Master/Slave:

5.1, the master and slave servers operate separately:

5.1.1, MySQL version consistent

5.1.2, initialize the table, start MySQL

5.1.3, set MySQL root password,/mysql/mysql-5.6/bin/mysqladmin-u root password ' 123456 '

5.2. Modify Master:

#vi/etc/my.cnf

[Mysqld]

Log-bin=mysql-bin #启用二进制日志

server-id=20 # server ID marked, master-slave inconsistency

5.3, modify Slave:

#vi/etc/my.cnf

[Mysqld]

Log-bin=mysql-bin #启用二进制日志

server-id=21 # server ID marked, master-slave inconsistency

5.2 Log in to MySQL master configuration

#/mysql/mysql-5.6/bin/mysql-uroot-p123456

Mysql>grant REPLICATION SLAVE on * * to 'Test' @ '% ' identified by ' 123456 ';

# generally do not use the root account, "%" means that all clients may be connected, as long as the account, the password is correct, this can be replaced by specific client IP , such as 192.168.209. enhance safety.

6, log on to the master server MySQL, query the status of master

Mysql>show Master status;

+------------------+----------+--------------+------------------+

| File | Position | binlog_do_db | binlog_ignore_db |

+------------------+----------+--------------+------------------+

|      mysql-bin.000007 |              |                  | |

+------------------+----------+--------------+------------------+

1 row in Set (0.00 sec)

Note: Get file and position.

7. Configure MySQL Slave from server:

Mysql>change Master to master_host= ' 192.168.209.19 ', master_user= 'test', master_password= ' 123456   ', master_log_file= ' mysql-bin.000007 ', master_log_pos=; # position of the primary server, no single quotes .

Mysql>start slave; To start the Copy from Server feature

8. Check the Slave Status:

Mysql> Show Slave Status\g

1. Row ***************************

Slave_io_state:waiting for Master to send event

master_host:192.168.209.19

Master_user:mysync

master_port:3306

Connect_retry:60

master_log_file:mysql-bin.000007

read_master_log_pos:320

relay_log_file:cdn20-relay-bin.000002

relay_log_pos:283

relay_master_log_file:mysql-bin.000007

Slave_io_running:yes

Slave_sql_running:yes

replicate_do_db:

replicate_ignore_db:

Replicate_do_table:

Replicate_ignore_table:

Replicate_wild_do_table:

Replicate_wild_ignore_table:

last_errno:0

Last_error:

skip_counter:0

exec_master_log_pos:320

relay_log_space:456

Until_condition:none

Until_log_file:

until_log_pos:0

Master_ssl_allowed:no

Master_ssl_ca_file:

Master_ssl_ca_path:

Master_ssl_cert:

Master_ssl_cipher:

Master_ssl_key:

seconds_behind_master:0

Master_ssl_verify_server_cert:no

last_io_errno:0

Last_io_error:

last_sql_errno:0

Last_sql_error:

Replicate_ignore_server_ids:

Master_server_id:20

master_uuid:6a36aa69-1c81-11e4-8213-b8ca3af2484f

Master_info_file:/mysql/mysql-5.6/data/master.info

sql_delay:0

Sql_remaining_delay:null

Slave_sql_running_state:slave have read all relay log; Waiting for the slave I/O thread to update it

master_retry_count:86400

Master_bind:

Last_io_error_timestamp:

Last_sql_error_timestamp:

MASTER_SSL_CRL:

Master_ssl_crlpath:

Retrieved_gtid_set:

Executed_gtid_set:

auto_position:0

1 row in Set (0.00 sec)

Slave_io and Slave_sql Process Yes state, otherwise it is the wrong state (such as: one of the No is an error).

At this point, the master-slave server configuration is complete.

9, the master-slave server test:

master server MySQL, build the database, and create a table in this library to insert a piece of data:

mysql> CREATE DATABASE test1;

Query OK, 1 row Affected (0.00 sec)

Mysql> Use Test1

Database changed

Mysql> CREATE TABLE test1 (ID int (4), name char (8));

Query OK, 0 rows affected (0.01 sec)

mysql> INSERT INTO test values (001, ' test1 ');

ERROR 1146 (42S02): Table ' test1.test ' doesn ' t exist

mysql> INSERT into test1 values (001, ' test1 ');

Query OK, 1 row Affected (0.00 sec)

mysql> show databases;

+--------------------+

| Database |

+--------------------+

| Information_schema |

| MySQL |

| Performance_schema |

| Test |

| Test1 |

+--------------------+

5 rows in Set (0.00 sec)

MySQL Query from server:

mysql> show databases;

+--------------------+

| Database |

+--------------------+

| Information_schema |

| MySQL |

| Performance_schema |

| Test |

| Test1 |

+--------------------+

5 rows in Set (0.01 sec)

At this point, MySQL master-slave configuration is complete, can be used normally, followed by joining the cluster mode.

Related Article

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.