MySQL双向复制简单配置步骤
MySQL从3.23版本起就已经内置了复制(Replication)的功能,我们可以配置成master-slave模式,也可以配置为master-master模式。方法
MySQL从3.23版本起就已经内置了复制(Replication)的功能,我们可以配置成master-slave模式,也可以配置为master-master模式。方法很简单,这里就master-master的配置简单的记录下来,我这里测试环境是mysql 5.1.31,一个是自己用源代码编译的,一个是用的xampp1.7里自带的。
首先找到两个版本相同的数据库服务器,最好是版本相同,或者差别太大(一个是3.x,一个是5.x,那估计没戏)。假设数据库的配置文件是/etc/my.cnf,我们假定A机的IP地址是192.168.0.1,B机的IP地址是192.168.0.2
我们在A机上给出一个授权用户,允许B机的某个账号拥有来获取要复制数据库的权利,这里假设针对所有的数据库都有复制的权利
mysql>grant file,replication slave on *.* to replicate@192.168.0.2 identified by ‘password’;
这样我们就创建了一个replicate的账号,密码是password。同样的方法在B机上也给A机一个授权
mysql>grant file,replication slave on *.* to replicate@192.168.0.1 identified by ‘password’;
接下来就是要修改配置文件了,首先打开A机的/etc/my.cnf文件,,在[mysqld]一段里,增加或者修改下面这些变量
server-id=1
log-bin=mysql-bin
master-host=192.168.0.2
master-user=replicate
master-password=password
保存退出。
同样的方法在B机上也做一遍,类似如下:
server-id=2
log-bin=mysql-bin
master-host=192.168.0.1
master-user=replicate
master-password=password
要注意,server-id千万别冲突了,当然,如果冲突了,数据库启动的时候会有报错的。
做完配置修改后,在重启数据库之前,我们还有做一件事请,那就是原始数据的同步,首先停止数据库,然后用A机的数据库全部覆盖B机的数据库(反之也行),总之,在重启之前,保证你需要同步的数据库应该是一致的(怎么说也得在同一个起跑线上嘛)。
好了,现在你可以重启你的数据库了。
你可以通过show master status; show slave status这样的SQL语句来查看对应的状态了。
版权声明:可以任意转载,转载时请务必以超链接形式标明文章原始出处和作者信息。
本文链接:

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











MySQL and phpMyAdmin are powerful database management tools. 1) MySQL is used to create databases and tables, and to execute DML and SQL queries. 2) phpMyAdmin provides an intuitive interface for database management, table structure management, data operations and user permission management.

Oracle is not only a database company, but also a leader in cloud computing and ERP systems. 1. Oracle provides comprehensive solutions from database to cloud services and ERP systems. 2. OracleCloud challenges AWS and Azure, providing IaaS, PaaS and SaaS services. 3. Oracle's ERP systems such as E-BusinessSuite and FusionApplications help enterprises optimize operations.

In MySQL, the function of foreign keys is to establish the relationship between tables and ensure the consistency and integrity of the data. Foreign keys maintain the effectiveness of data through reference integrity checks and cascading operations. Pay attention to performance optimization and avoid common errors when using them.

The main difference between MySQL and MariaDB is performance, functionality and license: 1. MySQL is developed by Oracle, and MariaDB is its fork. 2. MariaDB may perform better in high load environments. 3.MariaDB provides more storage engines and functions. 4.MySQL adopts a dual license, and MariaDB is completely open source. The existing infrastructure, performance requirements, functional requirements and license costs should be taken into account when choosing.

SQL is a standard language for managing relational databases, while MySQL is a database management system that uses SQL. SQL defines ways to interact with a database, including CRUD operations, while MySQL implements the SQL standard and provides additional features such as stored procedures and triggers.

Redis is a memory data structure storage system, mainly used as a database, cache and message broker. Its core features include single-threaded model, I/O multiplexing, persistence mechanism, replication and clustering functions. Redis is commonly used in practical applications for caching, session storage, and message queues. It can significantly improve its performance by selecting the right data structure, using pipelines and transactions, and monitoring and tuning.

Safely handle functions and regular expressions in JSON In front-end development, JavaScript is often required...

MySQL and phpMyAdmin can be effectively managed through the following steps: 1. Create and delete database: Just click in phpMyAdmin to complete. 2. Manage tables: You can create tables, modify structures, and add indexes. 3. Data operation: Supports inserting, updating, deleting data and executing SQL queries. 4. Import and export data: Supports SQL, CSV, XML and other formats. 5. Optimization and monitoring: Use the OPTIMIZETABLE command to optimize tables and use query analyzers and monitoring tools to solve performance problems.
