[Linux Mysql master-slave configuration] Organize the pits encountered by the master-slave configuration!

Note: -u: username -p: password --lock-all-tables: lock all tables during operation to prevent data modification during operation

1. Set up the mysql configuration file [I use the pagoda, so directly configure the settings in mysql in the software store]

Primary server: [mysqld]: log-bin = mysql-bin log_slave_updates = 1 skip-grant-tables [skip authentication authority] server-id = 1

Slave server: [mysqld]: log-bin = relay-bin server-id = 2 skip-grant-tables [skip authentication authority]

  Note: The port 3306 must be released, otherwise it will not be connected! After the configuration is successful, restart the mysql service; I clicked directly to restart manually!

2. Log in to mysql on the master server; create an account to use when synchronizing on the slave server;

  Create an account: create user 'user name' @ 'access host' identified by 'password';

  Grant permissions: grant permission list on database to 'user name' @ 'access host'; 【GRANT REPLICATION SLAVE ON *. * TO 'slave' @ '%' identified by 'slave';]

  Note: I have created the account and password in mysql, so directly use the permissions given to the created account in the second sentence; when granting permissions, you can directly grant permissions to the slave server root or sub-accounts under root;

After completion, use "FLUSH PRIVILEGES" to refresh;

3. Obtain binary log information at the main server terminal;

SHOW MASTER STATUS;

Note: File is the name of the log file used, Position is the file location used, these two parameters must be noted, it will be used when configuring the slave server

4. Enter the slave server, enter mysql, and set to connect to the master server

  change master to master_host = 'master server IP', master_user = 'account', master_password = 'password', master_log_file = 'mysql-bin.000008', master_log_pos = 107;

  • master_host: ip address of the main server Ubuntu;
  • master_log_file: the log file name of the master server previously queried;
  • master_log_pos: The location of the master server log file previously queried

 

5. Turn on synchronization and check the synchronization status

 

6. Test master-slave synchronization

Create a database in the main server mysql,

Check whether the new database exists in the slave server;

 

7. Other pits:

  Check whether the replication account exists and whether the permissions are granted: mysql> show grants for 'usvr_replication' @ '%';  

    +-----------------------------------------------------------------------------------------------------------------------------+
    | Grants for usvr_replication@%                                                                                               |
    +-----------------------------------------------------------------------------------------------------------------------------+
    | GRANT REPLICATION SLAVE ON *.* TO 'usvr_replication'@'%' IDENTIFIED BY PASSWORD '*F4039654D0AFD80BB0A7775938EFD47ACB809529' |
    +-----------------------------------------------------------------------------------------------------------------------------+
    1 row in set (0.00 sec)
    ————————————————

  Use the account from B to connect to A mysql -uusvr_replication -h 192.168.83.35 -p -P55944

  If the replication fails after the first attempt, the first link stop slave must be stopped during the second attempt;

  When the above method is done, the slave server permissions are not configured because the slave server is locked after the configuration is completed. When you add data to the table in the slave server, the master server data will not be changed.

 

Guess you like

Origin www.cnblogs.com/fengyinghui/p/12677065.html