欢迎进入Linux社区论坛,与200万技术人员互动交流 >>进入 mysql中实现master-slave同步: 第一步:分别在两台机子上各装一个mysql (本人测试机系统为unbutu,mysql5.5),如只有一台机器,需使mysql的端口不同(3306,3307)。 第二步:找到mysql 的my.cnf文件
欢迎进入Linux社区论坛,与200万技术人员互动交流 >>进入
mysql中实现master-slave同步:
第一步:分别在两台机子上各装一个mysql (本人测试机系统为unbutu,mysql5.5),如只有一台机器,需使mysql的端口不同(3306,3307)。
第二步:找到mysql 的my.cnf文件。
$cd /etc/mysql 进入该目录。
$ vim my.cnf 如是只读,且不允许修改。需用$ sudo vim my.cnf
第三步:修改my.cnf 中的配置项:
1 需做如下操作:
将bind-address=127.0.0.1 改为 bind-address=0.0.0.0
将#server-id=1
#log_bin=/var/log/mysql/mysql-bin.log
的注释(#)去掉。
添加:character-set-server=utf-8 #保证编码一致。
填加完成后,保存并退出即可。
第四步:
用root权限登录并创建slave数据库服务器用户:
$mysql -uroot -p
mysql>grant replication slave,replication client on *.* to liang@'192.168.10.21' indntified by 'liang';
mysql>grant replicatin slave on *.* to liang@'192.168.10.21' indntified by 'liang';
第五步:重启mysql服务。
$ sudo /etc/init.d/mysql restart #如不能正常启动,请检查my.cnf配置项以及mysql 的错误日志。
错误日志位置:/var/log/mysql/error.log
到此已将master配置完毕。
slave配置。
第六步:修改slave的my.cnf配置文件。
如下:
bind-address=0.0.0.0
server-id = 2
master-host = 192.168.10.24
master-user = liang
master-password = liang
master-port = 3306
log_bin = /var/log/mysql/mysql-bin.log
log-slave-updates
skip-slave-start
character-set-server=utf8
保存并退出.
第七步:重启slave的mysql服务器(同第五步)
本人在重启时出现错误,不能启动mysql.经查日志发现:如下错误(暂略)由于错误日志不在本机。以后补上,嘿嘿。
故将配置改为如下:
server-id = 2
#master-host = 192.168.10.24
#master-user = liang
#master-password = liang
#master-port = 3306
log_bin = /var/log/mysql/mysql-bin.log
log-slave-updates
skip-slave-start
character-set-server=utf8
保存并重启mysql,ok.
进入myslq,并在mysql中运行:
slave start;
第八步:在master中执行:
mysql>show master status\G;
显示内容为如下:
第九步:在slave中,运行如下命令:
mysql>change master to master_host='192.168.10.24', master_user='liang', master_password='liang', master_log_file='mysql-bin.000007', master_log_pos=170;
其中master_log_file,master_log_pos 为第八步中所显示的内容 .
mysql>slave start;
第十步:在master的中执行如下命令:
mysql>show slave status\G;
请查看Slave_IO_Running:YES
Slave_SQL_Running:YES
ok ,配置成功。
请出现Slave_IO_Running:Connectiong,请查看下面的错误信息或查看日志文件。
第十一步:测试
在主数据库中创建数据库:
mysql>create database ccc;
在slave中查看,如有ccc数据库,则说明同步成功。
同时可测创建表,修改表,添加记录等。一切OK.
最后谢谢网络上的朋友。在你们的帮助下,顺得完成。

Mastering the method of adding MySQL users is crucial for database administrators and developers because it ensures the security and access control of the database. 1) Create a new user using the CREATEUSER command, 2) Assign permissions through the GRANT command, 3) Use FLUSHPRIVILEGES to ensure permissions take effect, 4) Regularly audit and clean user accounts to maintain performance and security.

ChooseCHARforfixed-lengthdata,VARCHARforvariable-lengthdata,andTEXTforlargetextfields.1)CHARisefficientforconsistent-lengthdatalikecodes.2)VARCHARsuitsvariable-lengthdatalikenames,balancingflexibilityandperformance.3)TEXTisidealforlargetextslikeartic

Best practices for handling string data types and indexes in MySQL include: 1) Selecting the appropriate string type, such as CHAR for fixed length, VARCHAR for variable length, and TEXT for large text; 2) Be cautious in indexing, avoid over-indexing, and create indexes for common queries; 3) Use prefix indexes and full-text indexes to optimize long string searches; 4) Regularly monitor and optimize indexes to keep indexes small and efficient. Through these methods, we can balance read and write performance and improve database efficiency.

ToaddauserremotelytoMySQL,followthesesteps:1)ConnecttoMySQLasroot,2)Createanewuserwithremoteaccess,3)Grantnecessaryprivileges,and4)Flushprivileges.BecautiousofsecurityrisksbylimitingprivilegesandaccesstospecificIPs,ensuringstrongpasswords,andmonitori

TostorestringsefficientlyinMySQL,choosetherightdatatypebasedonyourneeds:1)UseCHARforfixed-lengthstringslikecountrycodes.2)UseVARCHARforvariable-lengthstringslikenames.3)UseTEXTforlong-formtextcontent.4)UseBLOBforbinarydatalikeimages.Considerstorageov

When selecting MySQL's BLOB and TEXT data types, BLOB is suitable for storing binary data, and TEXT is suitable for storing text data. 1) BLOB is suitable for binary data such as pictures and audio, 2) TEXT is suitable for text data such as articles and comments. When choosing, data properties and performance optimization must be considered.

No,youshouldnotusetherootuserinMySQLforyourproduct.Instead,createspecificuserswithlimitedprivilegestoenhancesecurityandperformance:1)Createanewuserwithastrongpassword,2)Grantonlynecessarypermissionstothisuser,3)Regularlyreviewandupdateuserpermissions

MySQLstringdatatypesshouldbechosenbasedondatacharacteristicsandusecases:1)UseCHARforfixed-lengthstringslikecountrycodes.2)UseVARCHARforvariable-lengthstringslikenames.3)UseBINARYorVARBINARYforbinarydatalikecryptographickeys.4)UseBLOBorTEXTforlargeuns


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

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

Zend Studio 13.0.1
Powerful PHP integrated development environment

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft
