Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to configure master-slave synchronization in mysql

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

In this issue, the editor will bring you about how to configure master-slave synchronization in mysql. The article is rich in content and analyzes and narrates it from a professional point of view. I hope you can get something after reading this article.

Master host:www IP:192.168.9.124

From host:www1 IP:192.168.9.123

# download mysql

Wget

# install mysql

Tar xzf mysql-5.1.58-linux-i686-glibc23.tar.gz

Useradd mysql

Mv 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 environment variables

Change the master and slave root passwords respectively

# mysql

Mysql > update mysql.user set password=password ('123456') where user= "root" and host= "localhost"

Www:

Mysql > grant all privileges on *. * to identified by '123456; # authorize 192.168.9.123 to log in to mysql

Mysql > flush privileges; # refresh permissions table

Mysql > exit

Testing from the server

Www1

# mysql-u root-h 192.168.9.124-p

Www

Mysql > FLUSH TABLES WITH READ LOCK; (main library plus lock)

Log and offset

Mysql > show master status

Mysqldump-p-- all-database-- lock-all-tables > db.sql

Www1

Scp-P.

# modify from my.cnf #

Server-id=2

Master-host=192.168.9.124

Master-user=slave

Master-password=123456

Master-port=3306

Log-bin=-bin

-

Restart mysql

Lsof-i 3306 | xargs kill-9

/ usr/local/mysql/bin/mysqld_safe-user=mysql &

Mysql-p

< db.sql # 导入db.mysql www mysql>

Unlock tables; (main library unlocked)

Mysql > show master status

Www1

Mysql > slave stop

Mysql > CHANGE MASTER TO MASTER_HOST='192.168.9.124', MASTER_USER='root'

MASTER_PASSWORD='123456',MASTER_LOG_FILE='mysql-bin.000001',MASTER_LOG_POS=548; (the following log_file log_pos refers to the log name and offset of the main library)

Mysql > slave start

Check the status

Mysql > show master status

Mysql > show slave status

Mysql > show processlist

Www

-An INPUT-s 192.168.9.123-p tcp-- dport 3306-j ACCEPT release 192.168.9.123 connection to port 3306

-An INPUT-p tcp-- dport 22-j ACCEPT # allow ssh

-An INPUT-j DROP # rejects all

This is how to configure master-slave synchronization in the mysql shared by the editor. If you happen to have similar doubts, you might as well refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report