为mysql快速添加从库,并为从库添加从库
现实情况下,mysql比较常见的是一主多从,而在主库出现问题是,需要将其从库升为主库,但事实上这种操作非常繁琐,基本上要对所有的从库进行操作。 既然如此,不妨将mysql做成ABC的结构,A为主库,B为A的从库,C是B的从库 这种情况,在A出现问题是,可以直接
现实情况下,mysql比较常见的是一主多从,而在主库出现问题是,需要将其从库升为主库,但事实上这种操作非常繁琐,基本上要对所有的从库进行操作。
既然如此,不妨将mysql做成ABC的结构,A为主库,B为A的从库,C是B的从库
这种情况,在A出现问题是,可以直接将B升为主库,其余下级从库将不需要任何操作。
这里记录一次此类操作,我这里的情况是,已经存在A和B,A是主,B是从
需求是,添加一个A的从库C,再添加一个C的从库D。
快速添加mysql从库(前提是都已经安装了相同版本的mysql)
首先将从库B的主从stop掉
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
|
然后将从库B的数据文件打包,分别拷贝到新的从库C和C的从库D下(sock和pid文件不要打包)
1 2 3 4 |
|
解压分别放在C和D的数据目录(删除主从信息文件)
1 2 3 |
|
修改C和D的配置文件的server-id,C为11 , D为21,(我这里有端口的区别,这个根据现实情况)
1 |
|
分别启动C和D
1 |
|
配置C和D的主从(一定要先配置好C和D的主从)
C:查看C的master信息
1 2 3 4 5 6 |
|
D:配置D的主从信息
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
|
修改C的主库同步信息(这里的主从信息要和stop B从库的信息一致)
1 2 3 4 |
|
最后启动B的主从!完成
验证:
通过show slave status\G;查看主从信息,SQL和IO线程是否为yes
最简单的验证就是在A里随便创建个库,然后show一下D里是否同步了。

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

AI Hentai Generator
Generate AI Hentai for free.

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



In MySQL database, the relationship between the user and the database is defined by permissions and tables. The user has a username and password to access the database. Permissions are granted through the GRANT command, while the table is created by the CREATE TABLE command. To establish a relationship between a user and a database, you need to create a database, create a user, and then grant permissions.

MySQL is suitable for beginners because it is simple to install, powerful and easy to manage data. 1. Simple installation and configuration, suitable for a variety of operating systems. 2. Support basic operations such as creating databases and tables, inserting, querying, updating and deleting data. 3. Provide advanced functions such as JOIN operations and subqueries. 4. Performance can be improved through indexing, query optimization and table partitioning. 5. Support backup, recovery and security measures to ensure data security and consistency.

To fill in the MySQL username and password: 1. Determine the username and password; 2. Connect to the database; 3. Use the username and password to execute queries and commands.

1. Use the correct index to speed up data retrieval by reducing the amount of data scanned select*frommployeeswherelast_name='smith'; if you look up a column of a table multiple times, create an index for that column. If you or your app needs data from multiple columns according to the criteria, create a composite index 2. Avoid select * only those required columns, if you select all unwanted columns, this will only consume more server memory and cause the server to slow down at high load or frequency times For example, your table contains columns such as created_at and updated_at and timestamps, and then avoid selecting * because they do not require inefficient query se

Navicat itself does not store the database password, and can only retrieve the encrypted password. Solution: 1. Check the password manager; 2. Check Navicat's "Remember Password" function; 3. Reset the database password; 4. Contact the database administrator.

View the MySQL database with the following command: Connect to the server: mysql -u Username -p Password Run SHOW DATABASES; Command to get all existing databases Select database: USE database name; View table: SHOW TABLES; View table structure: DESCRIBE table name; View data: SELECT * FROM table name;

Create a database using Navicat Premium: Connect to the database server and enter the connection parameters. Right-click on the server and select Create Database. Enter the name of the new database and the specified character set and collation. Connect to the new database and create the table in the Object Browser. Right-click on the table and select Insert Data to insert the data.

Copying a table in MySQL requires creating new tables, inserting data, setting foreign keys, copying indexes, triggers, stored procedures, and functions. The specific steps include: creating a new table with the same structure. Insert data from the original table into a new table. Set the same foreign key constraint (if the original table has one). Create the same index. Create the same trigger (if the original table has one). Create the same stored procedure or function (if the original table is used).
