Mysql master-slave synchronization Configuration

Source: Internet
Author: User

Master host: www IP: 192.168.9.124
From host: www1 IP: 192.168.9.123


# Download mysql
Wget http://dev.mysql.com/get/Downloads/MySQL-5.1/mysql-5.1.58-linux-i686-glibc23.tar.gz/from/ftp://mirror.anl.gov/pub/mysql/

# Install mysql
Tar xzf mysql-5.1.58-linux-i686-glibc23.tar.gz
Useradd mysql
Music mysql-5.1.58-linux-i686-glibc23/usr/local/mysql

Chown-R root.
Chown-R mysql data
Cp support-files/my-medium.cnf/etc/my. cnf
Bin/mysqld_safe -- user = mysql &
Cp support-files/mysql. server/etc/init. d/mysql. server
Cd

Export PATH = $ PATH:/usr/local/mysql/bin/# Add the environment variable

 

Change Master/Slave root passwords respectively
# Mysql
Mysql> update mysql. user set password = password ('000000') where user = "root" and host = "localhost ";

Www:
Mysql> grant all privileges on *. * to root@192.168.9.123 identified by '000000'; # authorize 192.168.9.123 to log on to mysql
Mysql> flush privileges; # refresh the permission table
Mysql> exit;

Test on slave server
Www1
# Mysql-u root-h 192.168.9.124-p


Www
Mysql> flush tables with read lock; (LOCK the master database)
Log and offset
Mysql> show master status;
Mysqldump-p -- all-database -- lock-all-tables> db. SQL


Www1
Scp-P root@192.168.9.124:/root/db. SQL.

######## Modify from my. cnf ############
Server-id = 2
Master-host = 192.168.9.124
Master-user = slave
Masters-password = 123456
Master-port = 3306
Log-bin = mysql-bin
-----------------------------------
Restart mysql
Lsof-I: 3306 | xargs kill-9
/Usr/local/mysql/bin/mysqld_safe -- user = mysql &


Mysql-p <db. SQL # import db. mysql

 

Www


Mysql> unlock tables; (unlock the master database)

Mysql> show master status;


Www1

Mysql> slave stop;

Mysql> change master to MASTER_HOST = '192. 168.9.124 ', MASTER_USER = 'root ',

MASTER_PASSWORD = '000000', MASTER_LOG_FILE = 'mysql-bin.000001 ', MASTER_LOG_POS = 123456; (later log_file log_pos refers to the log name and offset of the master database)

Mysql> slave start;

Check status

Mysql> show master status;

Mysql> show slave status;

Mysql> show processlist;

 


Www

-A input-s 192.168.9.123-p tcp -- dport 3306-j ACCEPT allow 192.168.9.123 to connect to port 3306

-A input-p tcp -- dport 22-j ACCEPT # Allow ssh

-A input-j DROP # reject all
Author "xavier"

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.