Home Database Mysql Tutorial Mysql master-slave synchronization configuration method

Mysql master-slave synchronization configuration method

Oct 25, 2017 pm 03:18 PM
mysql method Configuration

1. Install mysql on two Ubuntu machines
1. Check whether mysql is installed in the system

##This is already installed


If not installed, execute the previous command

==================================
MySQL Some simple management:

启动MySQL服务: sudo start mysql
停止MySQL服务: sudo stop mysql
修改 MySQL 的管理员密码: sudo mysqladmin -u root password newpassword
Copy after login

2. Configuration on the Master main server (103.251.237.42)

1. Edit my.cnf (command to find the file location: find / -name my.cnf )

Comment out bind-address in [mysqld] = 127.0.0.1 otherwise mysql cannot be remote

#server-id = 1 in 1 can be defined by yourself, but it needs to be kept unique and is the unique identification of the server

log_bin 启动MySQL二进制日志
binlog_do_db 指定记录二进制日志的数据库
binlog_ignore_db 指定不记录二进制日志的数据库。
Copy after login

##Comment out binlog_do_db and binlog_ignore_db, which means backing up all databasesAfter doing this After that, restart the database

2. Log in to the main server mysql and create the account and permissions used by the slave server;


@After that, the IP can access the main server, and the value here is set Create a new masterbackup user with the password masterbackup from the server IP

and grant replication slave permission


You can see that the user masterbackup has been added

3. View The status of the master database


Record mysql-bin.000007 and 276, write the following command for later use;

change master to master_host='103.251.237.42',master_port=3306,master_user ='masterbackup',master_password='masterbackup',master_log_file='mysql-bin.000007',master_log_pos=276;

3. Slave slave server configuration (103.251.237.45)
1. Edit my. cnf (command find file location: find / -name my.cnf)


In [mysqld]


relay-log = slave- relay-bin

relay-log-index = slave-relay-bin.index

It is not clear what this does. Add these two items.

Restart the mysql service


Log in to mysql and stop the synchronization command


Execute the command prepared above; Log in to the Slave server , connect to the Master server:


Restart data synchronization;


View Slave information; as shown in the figure If both sentences are yes, the status is normal

4. Test results from the master and slave servers


Create a database on the master server


Check the database just created on the slave server

You can find that the master-slave server configuration is complete.

================================================ ==================================================


Because the above is a mysql master-slave configuration for two new machines; there is no need to import the previous data from the master server to the slave server; then if the master server already has some data, you need to add the import from the master server Operation of data to slave server;

After configuring the master server to grant permissions to the slave server;

1. Execute the following command to lock the database to prevent data from being written;



This command is a global read lock. After executing the command, all tables in all libraries will be locked as read-only. It is generally used for database online backup. At this time, the write operation of the database will be blocked and the read operation can proceed smoothly;

2. Exit the mysql command line, export the database to the root file and name it all.sql;

3. Use the scp command to transfer the database file all.sql to From the server;

4. Connect to the database again and enter the mysql command to view the master status and record the values ​​of file and position;

5 .Unlock the data table;

Before configuring the slave server, import the data first;

1. Import the database of the master server;

2. The subsequent configuration is the same as the previous slave server configuration;

The above is the detailed content of Mysql master-slave synchronization configuration method. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP's big data structure processing skills PHP's big data structure processing skills May 08, 2024 am 10:24 AM

Big data structure processing skills: Chunking: Break down the data set and process it in chunks to reduce memory consumption. Generator: Generate data items one by one without loading the entire data set, suitable for unlimited data sets. Streaming: Read files or query results line by line, suitable for large files or remote data. External storage: For very large data sets, store the data in a database or NoSQL.

How to set font size on mobile phone (easily adjust font size on mobile phone) How to set font size on mobile phone (easily adjust font size on mobile phone) May 07, 2024 pm 03:34 PM

Setting font size has become an important personalization requirement as mobile phones become an important tool in people's daily lives. In order to meet the needs of different users, this article will introduce how to improve the mobile phone use experience and adjust the font size of the mobile phone through simple operations. Why do you need to adjust the font size of your mobile phone - Adjusting the font size can make the text clearer and easier to read - Suitable for the reading needs of users of different ages - Convenient for users with poor vision to use the font size setting function of the mobile phone system - How to enter the system settings interface - In Find and enter the "Display" option in the settings interface - find the "Font Size" option and adjust it. Adjust the font size with a third-party application - download and install an application that supports font size adjustment - open the application and enter the relevant settings interface - according to the individual

How to optimize MySQL query performance in PHP? How to optimize MySQL query performance in PHP? Jun 03, 2024 pm 08:11 PM

MySQL query performance can be optimized by building indexes that reduce lookup time from linear complexity to logarithmic complexity. Use PreparedStatements to prevent SQL injection and improve query performance. Limit query results and reduce the amount of data processed by the server. Optimize join queries, including using appropriate join types, creating indexes, and considering using subqueries. Analyze queries to identify bottlenecks; use caching to reduce database load; optimize PHP code to minimize overhead.

How to use MySQL backup and restore in PHP? How to use MySQL backup and restore in PHP? Jun 03, 2024 pm 12:19 PM

Backing up and restoring a MySQL database in PHP can be achieved by following these steps: Back up the database: Use the mysqldump command to dump the database into a SQL file. Restore database: Use the mysql command to restore the database from SQL files.

How to choose a mobile phone screen protector to protect your mobile phone screen (several key points and tips for purchasing mobile phone screen protectors) How to choose a mobile phone screen protector to protect your mobile phone screen (several key points and tips for purchasing mobile phone screen protectors) May 07, 2024 pm 05:55 PM

Mobile phone film has become one of the indispensable accessories with the popularity of smartphones. To extend its service life, choose a suitable mobile phone film to protect the mobile phone screen. To help readers choose the most suitable mobile phone film for themselves, this article will introduce several key points and techniques for purchasing mobile phone film. Understand the materials and types of mobile phone films: PET film, TPU, etc. Mobile phone films are made of a variety of materials, including tempered glass. PET film is relatively soft, tempered glass film has good scratch resistance, and TPU has good shock-proof performance. It can be decided based on personal preference and needs when choosing. Consider the degree of screen protection. Different types of mobile phone films have different degrees of screen protection. PET film mainly plays an anti-scratch role, while tempered glass film has better drop resistance. You can choose to have better

How to insert data into a MySQL table using PHP? How to insert data into a MySQL table using PHP? Jun 02, 2024 pm 02:26 PM

How to insert data into MySQL table? Connect to the database: Use mysqli to establish a connection to the database. Prepare the SQL query: Write an INSERT statement to specify the columns and values ​​to be inserted. Execute query: Use the query() method to execute the insertion query. If successful, a confirmation message will be output.

How to fix mysql_native_password not loaded errors on MySQL 8.4 How to fix mysql_native_password not loaded errors on MySQL 8.4 Dec 09, 2024 am 11:42 AM

One of the major changes introduced in MySQL 8.4 (the latest LTS release as of 2024) is that the "MySQL Native Password" plugin is no longer enabled by default. Further, MySQL 9.0 removes this plugin completely. This change affects PHP and other app

How to use MySQL stored procedures in PHP? How to use MySQL stored procedures in PHP? Jun 02, 2024 pm 02:13 PM

To use MySQL stored procedures in PHP: Use PDO or the MySQLi extension to connect to a MySQL database. Prepare the statement to call the stored procedure. Execute the stored procedure. Process the result set (if the stored procedure returns results). Close the database connection.

See all articles