Steps for building a mysql master-slave Cluster

Source: Internet
Author: User

Steps for building a mysql master-slave Cluster

Prerequisites: Four mysql databases need to be installed on linux, and the corresponding information must be configured. Mysql 01: master mysql 02: slave database slave01 mysql 03: slave database slave02 mysql 04: slave database slave03 Step 1: my. edit the binary file format on cnf: log-bin = mysql-bin; binary format: binlog-format = mixed Step 2: On the slave server: several slave servers need to be configured: Binary logs: each slave server is in my. configure binary log in cnf: relay-log = mysql-relay Note: my. for cnf, you must configure Step 3: configure server-id on the master server. The server-id of each server is unique and cannot be repeated. Generally, it is the number behind the IP address of each host. Master: server-id = 166 slave: server-id = 167, server-id = 168, server-id = 169, Step 4: if the database cannot be connected, run/usr/libexec/mysqlld -- skip-grant-tables to log on to the mysql database.. /Mysql-h 192.168.1.166-uroot-p-P 3306 (Port Number) Step 5: Enter the master database interface: grant permissions, create an account, and connect to and use it from the database, on the master database page: mysql> grant replication client, repliaction slave on *. * to 'xxxx' @ '192. 168. %. % 'identified by 'xxxxx': first, authorize the application to the slave database and create an account to connect to the slave database. You need to set the user name, password, and ip address for authorization, you need to check the status of the primary database on the primary database: mysql> show master status; Step 6: Access the created account of the primary database from the database: Go to each slave database interface: mysql> change master to master_host = '2017. xxxx. xxx. xxx ', Master_port = '000000', master_user = 'xxxxx', master_password = 'xxxxxxx', master_log_file = 'msyql-bin.000001 ', master_log_pos = 3306; master_log_file and master_log_pos must be changed based on the Status viewed on the primary database.
After running the preceding command, run the following command to view the Slave Data status:Mysql> show slave status \ G;You can see the connection details: if not, you can choose mysql> reset slave; mysql> stop slavw; and then continue to run the link information just now. Step 7: test the cluster Master/Slave database just created on the Desktop client, create a test database on the master database, and insert the test database into the database, check whether the slave database is displayed in the test database of the master database. If yes, the master-slave database cluster will be successfully built.
How to configure mysql master-slave synchronization configuration steps and code in LINUX

How can it be unstable? Our company is doing very well, but it is only one-way Master/Slave.
Open Baidu. Search for it. You may not be able to understand it if I paste code directly. Search for it. There are many online tutorials.

How to synchronize existing data in mysql master-slave synchronization,

-- The host opens two windows, one for mysql and the other for shell.
-- Host blocking write operations
Mysql> flush tables with read lock;
Query OK, 0 rows affected (0.00 sec)
Mysql>
Mysql>
Mysql> show master status;
+ ------------------ + ---------- + -------------- + ------------------ +
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+ ------------------ + ---------- + -------------- + ------------------ +
| Mysql-bin.000002 | 1529881 | openser | mysql, test |
+ ------------------ + ---------- + -------------- + ------------------ +
1 row in set (0.00 sec)
-- Export the host database in another window
Mysqldump-u root-p123456 -- opt-R openser> openser20121203. SQL
-- Unlock the window host just now
Mysql> unlock tables;
Query OK, 0 rows affected (0.00 sec)
Mysql>
-- Package data files to the slave machine
Drop database openser;
Create database openser;
Mysql-u root-p123456 openser <openser20121127. SQL
-- Slave operation
Slave stop;
Reset slave;
Change master to MASTER_HOST = '192. 168.21.26 ',
MASTER_USER = 'repl _ user ',
MASTER_PASSWORD = '000000 ',
MASTER_LOG_FILE = 'mysql-bin.000002 ',
MASTER_LOG_POS = 1529881;
Start slave;
Show slave status \ G

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.