Database -- one master and many slaves

Keywords: MySQL Database socket vim

Multiple real columns and one principal and many subordinate

Create a directory for database information

[root@db200 ~]# mkdir /data/330{7..9} –p

Create a file to hold the profile

[root@db01 ~]# touch /data/330{7..9}/my.cnf

Edit 3307 profile

[root@db01 ~]# vim /data/3307/my.cnf 
[mysqld] 
basedir=/application/mysql 
datadir=/data/3307/data 
socket=/data/3307/mysql.sock 
log_error=/data/3307/mysql.log 
log-bin=/data/3307/mysql-bin 
server_id=7 
port=3307 
[client] 
socket=/data/3307/mysql.sock   //Specifies the file of the 3307 database's sock

Edit 3308 profile

[root@db01 ~]# vim /data/3307/my.cnf 
[mysqld] 
basedir=/application/mysql 
datadir=/data/3308/data 
socket=/data/3308/mysql.sock 
log_error=/data/3308/mysql.log 
log-bin=/data/3308/mysql-bin 
server_id=8 
port=3308 
[client] 
socket=/data/3308/mysql.sock

Edit 3309 profile

[root@db01 ~]# vim /data/3309/my.cnf 
[mysqld] 
basedir=/application/mysql 
datadir=/data/3309/data 
socket=/data/3309/mysql.sock 
log_error=/data/3309/mysql.log 
log-bin=/data/3309/mysql-bin 
server_id=9 
port=3309 
[client] 
socket=/data/3309/mysql.sock

Initialize 3307 database

[root@db01 ~]#/application/mysql/scripts/mysql_install_db \ 
--user=mysql \ 
--defaults-file=/data/3307/my.cnf \ 
--basedir=/application/mysql --datadir=/data/3307/data

Initialize 3308 database

[root@db01 ~]#/application/mysql/scripts/mysql_install_db \ 
--user=mysql \ 
--defaults-file=/data/3308/my.cnf \ 
--basedir=/application/mysql --datadir=/data/3308/data

Initialize 3309 database

[root@db01 ~]#/application/mysql/scripts/mysql_install_db \ 
--user=mysql \ 
--defaults-file=/data/3309/my.cnf \ 
--basedir=/application/mysql --datadir=/data/3309/data

Modify authority

[root@db01]# chown -R mysql.mysql /data/330* 

Start real column

[root@db01]# mysqld_safe --defaults-file=/data/3307/my.cnf & 
[root@db01]# mysqld_safe --defaults-file=/data/3308/my.cnf & 
[root@db01]# mysqld_safe --defaults-file=/data/3309/my.cnf &

Login database

    [root@db01]# mysql -S /data/3307/mysql.sock -e "show variables like 'server_id'"
    [root@db01]# mysql -S /data/3308/mysql.sock -e "show variables like 'server_id'"
    [root@db01]# mysql -S /data/3309/mysql.sock -e "show variables like 'server_id'"

Above real column configuration (one master and many slaves)

3307 as the main library

[root@db01]# mysql -S /data/3307/mysql.sock -e "show variables like 'server_id'" / / log in to the main database

Authorization of the main database

grant replication slave on *.* to slave@'localhost' identified by '123';

View the status of the database

mysql> show master status;

To extract the file value and position value from the library.

Export the contents of the main library
mysqldump -uroot -p3307 -S /data/3307/mysql.sock -A >/root/3307.sql

Configuration of slave libraries (3308 and 3309 as slave libraries)

Import the contents of the master database, and the contents of the master and slave databases are highly consistent

mysql -uroot -p3308 -S /data/3308/mysql.sock </root/3307.sql

Landing database

mysql -S /data/3308/mysql.sock -e "show variables like 'server_id'"

Settings from library

mysql> change master to
    -> master_host='localhost',
    -> master_port=3307,
    -> master_user='slave',
    -> master_password='123',
    -> master_log_file='mysql-bin.000008',  // It must be consistent with the authorization table information of the main database
-> master_log_pos=521;                 // It must be consistent with the authorization table information of the main database

Status value view

mysql> start slave;
mysql> show slave status\G;

Master slave configuration succeeded

Import the contents of the master database, and the contents of the master and slave databases are highly consistent

mysql -uroot -p3309 -S /data/3309/mysql.sock </root/3307.sql

Landing database

mysql -S /data/3309/mysql.sock -e "show variables like 'server_id'"

Settings from library

mysql> change master to
    -> master_host='localhost',
    -> master_port=3307,
    -> master_user='slave',
    -> master_password='123',
    -> master_log_file='mysql-bin.000008',  // It must be consistent with the authorization table information of the main database
-> master_log_pos=521;                 // It must be consistent with the authorization table information of the main database

Status value view

mysql> start slave;
mysql> show slave status\G;

Master slave configuration succeeded

Posted by oaskedal on Sun, 08 Dec 2019 18:19:17 -0800