search
HomeDatabaseMysql TutorialMySQL主从复制详细讲解(二)快速实现_MySQL

<span style="font-size:18px;">简单步骤总结--快速实现:		

	一:主服务器的配置步骤:
	
		2:给从服务器设置授权用户
			grant all on *.* to user1@192.168.10.2 identified by "pass123";   (all表示所有权限的意思,授权所有的用户,关于数据库所有的表(只能是这台服务器192.168.10.2,如果主机是字符串单引号扩着&#39;leyangjunpc&#39;):账号是user1  密码是pass123)
                        GRANT REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO repl@&#39;192.168.0.%&#39; IDENTIFIED BY &#39;p4ssword&#39;;
		
		3:修改主数据库服务器的配置文件my.cnf/ini,开启bin-log日志,并设置server-id的值
			log-bin=mysql-bin
			server-id=1     (主从server-id一定要保证唯一,不能相同) --一主多从也一样		
	
	二:从服务器的配置步骤:
		
		1:配置文件中:修改数据库的server-id,注意server-id的值必须是唯一的,不能和主数据的配置相同,如果有多个
		   从服务器,每个从服务器必须有自己唯一的server-id值
		   开启bin-log
		
		2:Mysql版本从5.1.7以后开始就不支持&ldquo;master-host&rdquo;类似的参数
			在从库上执行如下命令;
			change master to master_host=&#39;masterIP&#39;, master_user=&#39;slave&#39;, master_password=&#39;slvaePASS&#39;;

			slave start;重启
			
		3:配置完后->检测是否和主服务器同步方法(数据同步成功不成功就看*):
			show slave status\G
			看到:* Salve_IO_Running :Yes   (表示成功的把主服务器的bin-log日志拿回来了且同步,写一行我就同步一行)
				  * Salve_SQL_Running :Yes  (拿过来的bin-log日志并成功的执行了sql语句,一主数据一致)
				  --看到为yes的说明已经和主服务器取得同步
				  master_Log_File:mysql-bin.00002    (同步过来的bin-log日志)
				  Read_Master_Log_Pos:106             (位置,show master status主看下就知道)
				  Connect_Retry:60                    (每隔60秒回去主服务器同步bin-log日志)
				  踪迹日志:
				  Relay-Log_File:localhost-relay-bin.00004   (从服务器生成的日志文件,不叫mysql-bin.xxx)
				  
			数据同步过来后,我们查询数据就可以去从服务器上查询不用去主服务器,减轻负载

能后你就可以尽情的玩你的主从复制啦,注意别在从服务器上乱删数据哦,要不能主从同步会有问题的,就够你玩的啦 
</span>

Statement
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
How do you alter a table in MySQL using the ALTER TABLE statement?How do you alter a table in MySQL using the ALTER TABLE statement?Mar 19, 2025 pm 03:51 PM

The article discusses using MySQL's ALTER TABLE statement to modify tables, including adding/dropping columns, renaming tables/columns, and changing column data types.

How do I configure SSL/TLS encryption for MySQL connections?How do I configure SSL/TLS encryption for MySQL connections?Mar 18, 2025 pm 12:01 PM

Article discusses configuring SSL/TLS encryption for MySQL, including certificate generation and verification. Main issue is using self-signed certificates' security implications.[Character count: 159]

How do you handle large datasets in MySQL?How do you handle large datasets in MySQL?Mar 21, 2025 pm 12:15 PM

Article discusses strategies for handling large datasets in MySQL, including partitioning, sharding, indexing, and query optimization.

What are some popular MySQL GUI tools (e.g., MySQL Workbench, phpMyAdmin)?What are some popular MySQL GUI tools (e.g., MySQL Workbench, phpMyAdmin)?Mar 21, 2025 pm 06:28 PM

Article discusses popular MySQL GUI tools like MySQL Workbench and phpMyAdmin, comparing their features and suitability for beginners and advanced users.[159 characters]

How do you drop a table in MySQL using the DROP TABLE statement?How do you drop a table in MySQL using the DROP TABLE statement?Mar 19, 2025 pm 03:52 PM

The article discusses dropping tables in MySQL using the DROP TABLE statement, emphasizing precautions and risks. It highlights that the action is irreversible without backups, detailing recovery methods and potential production environment hazards.

How do you create indexes on JSON columns?How do you create indexes on JSON columns?Mar 21, 2025 pm 12:13 PM

The article discusses creating indexes on JSON columns in various databases like PostgreSQL, MySQL, and MongoDB to enhance query performance. It explains the syntax and benefits of indexing specific JSON paths, and lists supported database systems.

How do you represent relationships using foreign keys?How do you represent relationships using foreign keys?Mar 19, 2025 pm 03:48 PM

Article discusses using foreign keys to represent relationships in databases, focusing on best practices, data integrity, and common pitfalls to avoid.

How do I secure MySQL against common vulnerabilities (SQL injection, brute-force attacks)?How do I secure MySQL against common vulnerabilities (SQL injection, brute-force attacks)?Mar 18, 2025 pm 12:00 PM

Article discusses securing MySQL against SQL injection and brute-force attacks using prepared statements, input validation, and strong password policies.(159 characters)

See all articles

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)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.