如何添加新数据库到MySQL主从复制列表
在LAMP架构中,我们一般使用MySQL作为数据库,而MySQL主从也是 高性能网站 架构中必要的环节(如 drupal 、Wordpress等架构的网站)。本文大概讲解一下MySQL主从的复制以及出现的问题。 MySQL主从复制一般情况下我们会设置需要同步的数据库,使用参数配置选
在LAMP架构中,我们一般使用MySQL作为数据库,而MySQL主从也是高性能网站架构中必要的环节(如drupal、Wordpress等架构的网站)。本文大概讲解一下MySQL主从的复制以及出现的问题。
MySQL主从复制一般情况下我们会设置需要同步的数据库,使用参数配置选项,binlog-do-db,可以在master上指定需要同步的数据库,replicate-do-db在从数据看上指定需要同步的数据库。(一般只设定master上的binlog-do-db即可,不需要两个同时设定。以防万一,在slave也可以加上replicate-ignore-db)。
我们遇到的问题是,在master上面新增了一个数据库,这个时候如何把新加的这个数据库添加到MySQL的主从复制链里?(即不重新复制整个库的情况下,重新设置主从复制)。
首先,我们大概罗列一下主从复制的基本步骤,(MySQL主从首先需要在各自服务器配置好)。
1. 复制数据库。
mysqldump --master-data --single-transaction -R --databases [db_name] | gzip -9 - | pv > all-db-with-master-data.sql.gz
注意:innodb用 –single-transaction, myisam需要用 –lock-all-tables。
2. 复制,导入数据。
pv <p>3. 启动slave数据库。</p> <p class="wp_syntax"></p><p class="code"></p><pre class="brush:php;toolbar:false">slave start
注意:切换到主的语句已经在导出的sql语句里面了,注意查看。change master to master_log_file=’(binlog name in relay_master_log_file)’, master_log_pos=(exec_master_log_pos number)。
那么,在现有的主从复制结构中,如何增加一个新的数据库进去?比如我们要增加一个数据库在master服务器上,比如,名为newdb的数据库。
具体操作如下:
1. 从服务上,停掉slave数据库。
stop slave;
2. 主服务器上,导出新数据库。
mysqldump --master-data --single-transaction -R --databases newdb > newdb.sql
3. 主服务器上,修改my.cnf文件,添加新库到binlog-do-db参数,重启mysql。
4. 在导出的newdb.sql里面查找当前的日志文件以及位置(change master to …)
然后让slave服务器执行到这个位置。
start slave until MASTER_LOG_FILE="mysql-bin.000001", MASTER_LOG_POS=1222220;
其中MASTER_LOG_FILE以及MASTER_LOG_POS在导出的数据库newdb.sql顶部位置查找。
4. 导入新库到从服务器上。
mysql <p>5. start slave</p> <p>其中比较重要的是在主服务器上导出新库时的日志位置(position A),这个点很重要,以这个点做为分界线,导入新库。</p> <p>这种方法也同样适用于某个数据库或者某个数据表不同步的情况,比如主从数据库有一个表由于某些原因数据不一致,那么上面的方法只需要去掉重启数据库一步,其他的操作基本</p> <p class="copyright"> 原文地址:如何添加新数据库到MySQL主从复制列表, 感谢原作者分享。 </p>

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.
