将主服务器中的MySql数据库同步到从服务器中,使得对主服务器的操作可以即时更新到从服务器,避免主服务器因环境或者网络异常一时无法使用,达到备份效果,这篇文章整理的确实挺详细的
一、目的:将主服务器中的MySql数据库同步到从服务器中,使得对主服务器的操作可以即时更新到从服务器,避免主服务器因环境或者网络异常一时无法使用,达到备份效果。二、环境:
主从服务器操作系统、数据库版本均相同,具体如下:
操作系统:Windows 2003 Server R2
MySql数据库版本:5.0.51b
主服务器(用A代替)IP地址:192.168.4.100
从服务器(用B代替)IP地址:192.168.4.101
三、配置过程:
1、在A创建远程访问备份账户。
在A的MySql数据库中建立一个备份账户,命令如下:
代码如下:
mysql> GRANT REPLICATION SLAVE,RELOAD,SUPER ON *.* TO july@'192.168.4.101' IDENTIFIED BY '123456';
mysql> Flush privileges;
mysql> Quit;
语句解释:
第一句中*.*表示所有数据库,如果要对某个数据库备份的话,假如数据库名称为some,则要换成some.*,其中 TO july@'192.168.4.101',july为远程访问用户名,IP地址为远程访问IP,BY '123456'中123456为远程访问密码;
第二句语句执行后使得远程访问用户创建生效;
执行说明:
执行上述语句后,若要看远程访问用户是否已经创建成功,执行以下语句:
mysql> use mysql;
mysql> select host,user from user;
用户列表中多了一条
+------------------------------------+------------------+
|host |user |
+------------------------------------+------------------+
|192.168.4.101 |july |
+------------------------------------+------------------+
至此,说明远程访问用户已经创建成功。
2、关闭A的MySql服务并拷贝数据到B。
关闭A的Mysql服务,将A中的数据拷贝到B中,使得A、B服务器初始数据完全相同,并且在同步备份之前禁止对服务器中进行数据库写入操作,以保证A、B服务器的初始数据完全相同。
3、修改A中my.ini配置信息
打开my.ini文件,在[mysqld]下添加以下内容(#内容为注释):
# server-id:A服务器的ID值
server-id=10
#log-bin:二进制变更日志
log-bin=c:\log/log-bin.log
4、重启A服务器。
5、关闭B服务器,对B的my.ini进行相关配置
此处需要注意:
由于设置了slave的配置信息,mysql在数据库data目录下生成master.info,所以如有要修改相关slave的配置要先删除该文件,否则修改的配置不能生效。
打开B的my.ini配置文件,在[mysqld]中添加以下内容:
#B服务器ID值
server-id=11
#远程访问IP地址
master-host=192.168.4.100
#远程访问用户名
master-user=july
#远程访问用户密码
master-password=123456
#主服务器端口(默认为3306,此处要注意主服务器端口是否因为防火墙被禁止)
master-port=3306
#同步时间间隔为60秒
master-connect-retry=60
#设置要同步备份的数据库,此处数据库为some
replicate-do-db=some
6、重启B服务器,到此已完成主从备份,如果有错误,可以通过mysql_error.log进行查看。
说明:此文档为网络搜集资料自行试验整理,主要是方便自己后续查找以及有需要者参考,若有侵权之处,联系即删除。

MySQL's position in databases and programming is very important. It is an open source relational database management system that is widely used in various application scenarios. 1) MySQL provides efficient data storage, organization and retrieval functions, supporting Web, mobile and enterprise-level systems. 2) It uses a client-server architecture, supports multiple storage engines and index optimization. 3) Basic usages include creating tables and inserting data, and advanced usages involve multi-table JOINs and complex queries. 4) Frequently asked questions such as SQL syntax errors and performance issues can be debugged through the EXPLAIN command and slow query log. 5) Performance optimization methods include rational use of indexes, optimized query and use of caches. Best practices include using transactions and PreparedStatemen

MySQL is suitable for small and large enterprises. 1) Small businesses can use MySQL for basic data management, such as storing customer information. 2) Large enterprises can use MySQL to process massive data and complex business logic to optimize query performance and transaction processing.

InnoDB effectively prevents phantom reading through Next-KeyLocking mechanism. 1) Next-KeyLocking combines row lock and gap lock to lock records and their gaps to prevent new records from being inserted. 2) In practical applications, by optimizing query and adjusting isolation levels, lock competition can be reduced and concurrency performance can be improved.

MySQL is not a programming language, but its query language SQL has the characteristics of a programming language: 1. SQL supports conditional judgment, loops and variable operations; 2. Through stored procedures, triggers and functions, users can perform complex logical operations in the database.

MySQL is an open source relational database management system, mainly used to store and retrieve data quickly and reliably. Its working principle includes client requests, query resolution, execution of queries and return results. Examples of usage include creating tables, inserting and querying data, and advanced features such as JOIN operations. Common errors involve SQL syntax, data types, and permissions, and optimization suggestions include the use of indexes, optimized queries, and partitioning of tables.

MySQL is an open source relational database management system suitable for data storage, management, query and security. 1. It supports a variety of operating systems and is widely used in Web applications and other fields. 2. Through the client-server architecture and different storage engines, MySQL processes data efficiently. 3. Basic usage includes creating databases and tables, inserting, querying and updating data. 4. Advanced usage involves complex queries and stored procedures. 5. Common errors can be debugged through the EXPLAIN statement. 6. Performance optimization includes the rational use of indexes and optimized query statements.

MySQL is chosen for its performance, reliability, ease of use, and community support. 1.MySQL provides efficient data storage and retrieval functions, supporting multiple data types and advanced query operations. 2. Adopt client-server architecture and multiple storage engines to support transaction and query optimization. 3. Easy to use, supports a variety of operating systems and programming languages. 4. Have strong community support and provide rich resources and solutions.

InnoDB's lock mechanisms include shared locks, exclusive locks, intention locks, record locks, gap locks and next key locks. 1. Shared lock allows transactions to read data without preventing other transactions from reading. 2. Exclusive lock prevents other transactions from reading and modifying data. 3. Intention lock optimizes lock efficiency. 4. Record lock lock index record. 5. Gap lock locks index recording gap. 6. The next key lock is a combination of record lock and gap lock to ensure data consistency.


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

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SublimeText3 English version
Recommended: Win version, supports code prompts!

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

Atom editor mac version download
The most popular open source editor