MySQL Master-slave configuration

Source: Internet
Author: User

1. Create a replication user on Master

to enter the MySQL environment, execute the following MySQL statement:

mysql> Create user Repl_user;

Query OK, 0 rows Affected (0.00 sec)

mysql> grant replication Slave on * * to ' backup ' @ ' 192.168.1.145 ' identified by ' 123456 ';

Query OK, 0 rows Affected (0.00 sec)

The IP address is the address from the server, andbackup is the user name of master to slave .


2. turn on the binary log on Master

Vim/etc/my.cnf

[Mysqld]

Log-bin=master-bin

Log-bin-index=master-bin.index

Server-id=1

Server-id cannot be duplicated with Server-id from the server .


3. Configuring the slave server

Vim/etc/my.cnf

[Mysqld]

server-id=2

Relay-log=slave-relay-bin

Relay-log-index=slave-relay-bin.index

The order of the three rows must be as above.


4. Go to slave MySQL console for master and slave setup

Mysql> Change Master to

-master_host = ' 192.168.1.144 ',

-Master_port = 3306,

-Master_user = ' backup ',

-Master_password = ' 123456 ';

Query OK, 0 rows affected (0.10 sec)

Master_host is the IP address of the primary server .


5. Turn on the slave server

mysql> start slave;

Query OK, 0 rows Affected (0.00 sec)


6. View the status from the server

Mysql> show Slave status\g;

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

Slave_io_state:waiting for Master to send event

master_host:192.168.1.144

Master_user:backup

master_port:3306

Connect_retry:60

master_log_file:master-bin.000001

read_master_log_pos:106

relay_log_file:slave-relay-bin.000002

relay_log_pos:252

relay_master_log_file:master-bin.000001

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:106

relay_log_space:407

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:

1 row in Set (0.00SEC)

If these two items show OK to indicate that the configuration was successful.




This article is from the "Operational Work Notes" blog, make sure to keep this source http://yyyummy.blog.51cto.com/8842100/1537050

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.