1. Install the latest version of Ubuntu Server and update the system.
2. Install the MySQL server:sudo apt-get instal mysql-server, then set the administrator password and remove the local address bindings so that remote access can be made.
Main: 192.168.137.12
From: 192.168.137.13
3. Set up UTF8 character set to support Chinese, in the master-slave server configuration file/etc/mysql/my.cnf add:
The code is as follows |
Copy Code |
[Client] Default-character-set = UTF8 [Mysqld] Default-character-set = UTF8 Init_connect = ' SET NAMES UTF8; ' |
4. Start the backup in the server. First, add the following content to the primary server in the configuration file. Where S3 (for example) is a database that needs to be synchronized.
The code is as follows |
Copy Code |
[Mysqld] Log-bin = Mysql-bin Server-id = 1 BINLOG-DO-DB = S3 |
5. Restart the primary database.
The code is as follows |
Copy Code |
sudo service start MySQL
|
6. Connect to the primary database and create the database you need to sync, if it already exists you can ignore this step.
The code is as follows |
Copy Code |
Mysql–u root–p Create DATABASE S3;
|
7. Add an account (sync) to the server to synchronize the database and give the permissions from the backup important.
The code is as follows |
Copy Code |
Grant replication slave on *.* to ' sync ' @ '% ' identified by ' 12345 '
|
8. Record the log file name and location of the S3 database for the location from which to start the machine backup.
The code is as follows |
Copy Code |
Mysql> Show master status; +------------------+----------+--------------+------------------+ | File | Position | binlog_do_db | binlog_ignore_db | +------------------+----------+--------------+------------------+ | mysql-bin.000007 | 106 | S3 | | +------------------+----------+--------------+------------------+
|
9. Modify the configuration file from the machine.
The code is as follows |
Copy Code |
[Mysqld] Server-id = 2 Read-only Master-connect-retry = 60 REPLICATE-DO-DB = S3
|
10. Reboot from the machine, create a new database (S3), or restore the database from the original database. and execute the command:
The code is as follows |
Copy Code |
Change Master to master_host= ' 192.168.137.12 ', master_user= ' sync ', master_password= ' 12345 ', master_log_file= ' Mysql-bin.000007 ', master_log_pos=106;
|
11. Start Backup from the machine and view the machine status.
The code is as follows |
Copy Code |
Start slave; show slave statusg; 1. Row *************************** Slave_io_state:waiting for Master to send event master_host:192.168.137.12 Master_user:sync master_port:3306 Connect_retry:60 master_log_file:mysql-bin.000007 read_master_log_pos:106 relay_log_file:s3-db-slave-1-relay-bin.000010 relay_log_pos:251 relay_master_log_file:mysql-bin.000007 Slave_io_running:yes Slave_sql_running:yes Replicate_do_db:s3 replicate_ignore_db: Replicate_do_table: Replicate_ignore_table: Replicate_wild_do_table: Replicate_wild_ignore_table: last_errno:0 Last_error: skip_counter:0 exec_master_log_pos:106 relay_log_space:559 Until_condition:none Until_log_file: until_log_pos:0 Master_ssl_allowed:no Master_ssl_ca_file: Master_ssl_ca_path: Master_ssl_cert: Master_ssl_cipher: Master_ssl_key: seconds_behind_master:0 Master_ssl_verify_server_cert:no last_io_errno:0 Last_io_error: last_sql_errno:0 Last_sql_error: 1 row in Set (0.00 sec) Slave_io_running:yes Slave_sql_running:yes |
Indicates that the work is working properly, no problem occurs. A problem-critical resolution tool is to view logging.
The code is as follows |
Copy Code |
Cat/var/log/mysql/error.log |