How to deploy master-slave architecture in MySQL5.7 database
This article will explain in detail how to deploy the master-slave architecture in the MySQL5.7 database. The content of the article is of high quality, so the editor shares it for you as a reference. I hope you will have a certain understanding of the relevant knowledge after reading this article.
1. Create a mysql user: useradd-m-d / home/mysql mysql
2. Upload the mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz installation package to the / app directory.
With official download link: https://dev.mysql.com/downloads/file/?id=476936
3. Extract the installation package to tar-zxvf mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz in the / app directory.
4. Rename the extracted installation package to: mysql5722
Mv mysql-5.7.22-linux-glibc2.12-x86_64 mysql5722
5. Go to the mysql5722 directory to create data and logs directories.
Cd mysql5722/ mkdir data & & mkdir logs
6. Go to the logs directory you just created to create a log file
Cd logs touch error.log & & touch general.log authorization / app/mysql5722 directory main subordinate group is mysql chown-R mysql:mysql / app/mysql5722
7. Enter the bin directory of mysql to make initialization settings:
Cd.. / bin/. / mysqld-- initialize-- user=mysql-- basedir=/app/mysql5722/-- datadir=/app/mysql5722/data
Note: root users will be prompted to save their default password during initialization, which is required for the first login.
8. Create a mysql configuration file:
Cd / etc/&& mv my.cnf my.cnf.bak
Create a new configuration file: touch my.cnf, with the following contents:
The contents of the Master node profile:
[mysqld] server-id=1 log_bin=master-bin log_bin_index=master-bin.index binlog_do_db=mysql expire_logs_days=7 # skip-grant-tables lower_case_table_names=1 explicit_defaults_for_timestamp port = 3306 datadir = / app/mysql5722/data socket = / app/mysql5722/mysql.sock user = mysql symbolic-links = 0 basedir = / app/mysql5722 big-tables character-set-server = utf8 # general-log-file = / app/mysql5722/logs/general.log language = / app/mysql5722/share Lc-messages-dir = / app/mysql5722/share general-log = on # GENERAL_LOG=ON general-log-file = / app/mysql5722/logs/mysqld.log slow-query-log = 1 pid-file = / app/mysql5722/mysql.pid slow-query-log-file = / app/mysql5722/logs/mysqld_slow.log slave-load-tmpdir = / app/mysql5722/tmp plugin-dir = / app/mysql5722/lib/plugin max_connections = 1000 # innodb # innodb_log_file_size=512M # innodb_buffer_ Pool_size=2G [mysqld_safe] log-error=/app/mysql5722/logs/mysql_error.log pid-file=/app/mysql5722/mysql.pid [client] port = 3306 socket=/app/mysql5722/mysql.sock user=mysql
9. Configure startup commands:
Cd / app/mysql5722/support-files/ cp mysql.server / etc/init.d/mysqld cd / etc/init.d/
Modify the contents of the mysqld configuration file to add the following two lines of information:
10. Configure boot boot
Chkconfig-- add mysqld chkconfig mysqld on chown-R mysql:mysql mysql5722/
11. Start the mysql database
Service mysqld start
12. Log in to mysql
. / mysql-uroot-paired LRabRterterxaS9lh'
Change the root default password, otherwise the sql cannot be executed:
. / mysql-uroot-paired LRabRitter xaS9lh' modify the root default password, otherwise you cannot execute sql: alter user user () identified by "Abcd@123"; change the root user password flush privileges; to refresh user mysql; create user 'master'@'%' identified by' Abcd@123'; grant replication slave on *. * to 'master'@'%'; flush privileges show master status
Prepare the slave node configuration file:
[mysqld] server-id=2 relay_log=slave-relay-bin relay_log_index=slave-relay-bin.index basedir=/app/mysql5722 datadir=/app/mysql5722/data socket=/app/mysql5722/mysql.sock user=mysql character-set-server=utf8 lower_case_table_names=1 explicit_defaults_for_timestamp port=3306 general-log=1 general-log-file=/app/mysql5722/logs/general.log slow-query-log=1 long_query_time=1 slow_query_log_file=/app/mysql5722/slowquery.log pid-file=/app/mysql5722/mysql.pid Slave-load-tmpdir=/app/mysql5722/slavetmp max_connections=1000 # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 # skip-grant-tables [mysqld_safe] log-error=/app/mysql5722/logs/error.log pid-file=/app/mysql5722/mysql.pid [client] port=3306 socket=/app/mysql5722/mysql.sock user=mysql
Restart the slave node mysql after saving.
Slave: (slave) configuration:
After logging in to mysql, execute:
User mysql; change master to master_host='10.1.60.71',master_user='master',master_password='abcd@123',master_log_file='master-bin.000001',master_log_pos=154; show slave status\ G
Make sure that the following two values are YES, indicating that master-slave replication has been successfully configured. Note that the firewall policy of the two servers and the network must be interconnected.
Slave_IO_Running:YES Slave_SQL_Running:YES on how to deploy the master-slave architecture in the MySQL5.7 database is shared here. I hope the above content can be helpful to you and learn more knowledge. If you think the article is good, you can share it for more people to see.