MySQL Master-slave configuration

Source: Internet
Author: User

1, configuration of the first MySQL, has been installed before MySQL does not record

2. copy MySQL master directory

Cd/usr/local

Cp-r MySQL Mysql_slave

CD Mysql_slave

3. Initialize mysql_slave./scripts/mysql_install_db --user=mysql --datadir=/data/mysql_slave4, copy Mysql_ Slave configuration file and edit cd /usr/local/mysql_slavecp /etc/my.cnf  ./my.cnfvim my.cnf modify port = 3306 instead of port =3307 modify Socket        = /tmp/mysql.sock to socket         = /tmp/mysql_slave.sock Increase datadir        =/data/mysql_slave5, copy boot files and configure Cp /etc/init.d/mysqld /etc/init.d/mysqld_slave6, Start MySQL boot mysql_slave/etc/init.d/mysqld start/etc/init.d/mysqld_slave start7, Copy the data on the MySQL library on the master database to Db1mysqldump -s /tmp/mysql.sock mysql > 123.sqmysql -s &NBSP;/TMP/MYSQL.SOCK&NBSP;&NBSP;DB1&NBSP;&LT;123.SQL8, configuring the master configuration file vim /etc/my.cnf server-id        = 1log-bin=river9, restart service/etc/init.d/mysqld restart10, master database add authorization Mysqlmysql > grant replication slave on *.* to  ' repl ' @127.0.0.1 identified by  ' abc.123 ';mysql> flush privileges; Mysql> flush tables with read lock;mysql> show maste stats;11, Edit from database configuration file vim /usr/local/mysql_slave/my.cnfserver-id       =  11112. Import the library file from the database mysql -s /tmp/mysql_slave.sock -e  "CREATE&NBSP;DATABASE&NBSP;DB1" # Log in and create a database db1mysql -s /tmp/mysql_slave.sock db1 <123.sql  #导入123. SQL to db113, Configure the Mysql -s /tmp/ -s /tmp/mysql_slave.sock mysql> slave stop;mysql from the database > change master to master_host= ' 127.0.0.1 ',  master_port=3306, master_user= ' Repl ',  master_password= ' abc.123 ',  master_log_file= ' river.000001 ',  master_log_pos=330;# This step requires viewing master_log_file= ' river.000001 ',  master_log_pos=330 need to use Show master stats command 14 on the primary server, Re-login to view master-slave status/ETC/INIT.D/MYSQLD_SLAVE&NBSP;RESTARTMYSQL&NBsp;-s /tmp/ -s /tmp/mysql_slave.sockmysql> slave startmysql> show  slave status\g; slave_io_running: yes slave_sql_running: yes# These two places are shown as Yes successfully  15, Test Master   Login main database, delete table  mysql mysql>unlock tables; mysql>use db1 mysql> drop help_category  #登陆从数据库查看已经没有help_category表   #记住不能在从数据库上写入否则会导致数据错乱

This article is from the "愺 Burgundy pounding his 豩" blog, please be sure to keep this source http://riverxyz.blog.51cto.com/533303/1785559

MySQL Master-slave configuration

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.