Redhat
MySQL从3.23.15版本以后提供数据库复制功能,利用该功能可以实现两个数据库同步,主从模式,互相备份模式的功能。实现数据同步备份。数据库同步复制功能的设置都在mysql的设置文件中体现。mysql的配置文件(一般是my.cnf) 在Linux环境下在/etc/my.cnf 或者在mysql用户的home目录下面的my.cnf.
设置方法:
操作系统: RedHat Linux 9 mysql:mysql-standard-4.0.18-pc-linux-i686.tar.gz
A Server: 192.168.0.1 主服务器master
B Server: 192.168.0.10 副服务器slave
A上已安装好MySQL且已有数据库,在B上安装mysql-standard-4.0.18, 安装步骤可解压后按INSTALL-BINARY上方法安装mysql,我将其然后启动 mysql.
A服务器设置
#mysql ?u root ?p Master开放一个账号dbbackup密码123456给IP:192.168.0.10有档案处理的权限. mysql>GRANT ALL ON *.* TO dbbackup@192.168.0.10 IDENTIFIED BY‘123456’ mysql>exit
#mysqladmin ?u root ?p shutdown
备份Master所有数据库..通常都用tar指令. (注意:tar的时候,MySQL是要在stop情况下)
#tar zcvf /tmp/mysql.tar.gz /usr/local/src/mysql/data
在A机器上修改/etc/my.cnf
[mysqld]
log-bin (生成.index文件。#设置需要记录log 可以设置log-bin=c:/mysqlbak/mysqllog 设置日志文件的目录,
#其中mysqllog是日志文件的名称,mysql将建立不同扩展名,文 件名为mysqllog的几个日志文件。)
server-id=1
sql-bin-update-same
binlog-do-db=forimage (#指定需要日志的数据库为forimage)
启动A服务器mysql: Bin/mysqld-safe ?user=mysql server-id=1 & (要指定server-id)
此时由于加入log-bin参数,因此开始生成index文件,在/usr/local/src/mysql/data目录下有.index文件。档案纪录数据库的异动log. #mysql ?u root ?p 用show master status 命令看日志情况。
B服务器设置
设定/etc/my.cnf
[mysqld]
master-host=192.168.0.1
master-user=dbbackup (#同步用户帐号)
master-password=123456
master-port=3306
server-id=2
master-connect-retry=60 (预设重试间隔为60秒 )
replicate-do-db=forimage (只对数据库forimage更新 )
log-slave-updates
copy A上的/tmp/mysql.tar.gz 到B上的MySQL安装目录的data/下,并解压缩覆盖data/
#chown ?R mysql /usr/local/src/mysql/data/
#cd /usr/local/src/mysql/
#chown ?R root:mysql .
重启B服务器的mysql: #bin/mysqladmin ?u root shutdown #bin/mysql-safe ?user=mysql server-id=2 & (要指定server-id,与my.cnf对应)
show slave status看同步配置情况。
#bin/mysql ?u root
则在/usr/local/src/mysq/data/目录会出现master.info,此文件纪录了Master MySQL server的信息. 如有要修改相关slave的配置要先删除该文件. 否则修改的配置不能生效。
状况测试:
1.A跟B网络及服务都正常情况下,由A端变化数据后,到B端浏览数据,检查是否有数据变化。
2.模拟B当机,或是B不一定需要一直跟A有连接.将由A端变化数据后,到B端浏览数据,B点应该是没有数据变化的。
双机互备模式
如果在A加入slave设置,在B加入master设置,则可以做B->A的同步。
在A的配置文件中 mysqld 配置项加入以下设置:
master-host=10.10.10.53
master-user=backup
master-password=1234
replicate-do-db=backup
master-connect-retry=10
在B的配置文件中 mysqld 配置项加入以下设置:
log-bin=c:/mysqllog/mysqllog
binlog-do-db=backup
注意:当有错误产生时*.err日志文件。同步的线程退出,当纠正错误后要让同步机制进行工作,运行slave start
重启AB机器,则可以实现双向的热备。
测试:
向B批量插入大数据量表AA(1872000)条, A数据库每秒钟可以更新2500条数据

MySQLdiffersfromotherSQLdialectsinsyntaxforLIMIT,auto-increment,stringcomparison,subqueries,andperformanceanalysis.1)MySQLusesLIMIT,whileSQLServerusesTOPandOracleusesROWNUM.2)MySQL'sAUTO_INCREMENTcontrastswithPostgreSQL'sSERIALandOracle'ssequenceandt

MySQL partitioning improves performance and simplifies maintenance. 1) Divide large tables into small pieces by specific criteria (such as date ranges), 2) physically divide data into independent files, 3) MySQL can focus on related partitions when querying, 4) Query optimizer can skip unrelated partitions, 5) Choosing the right partition strategy and maintaining it regularly is key.

How to grant and revoke permissions in MySQL? 1. Use the GRANT statement to grant permissions, such as GRANTALLPRIVILEGESONdatabase_name.TO'username'@'host'; 2. Use the REVOKE statement to revoke permissions, such as REVOKEALLPRIVILEGESONdatabase_name.FROM'username'@'host' to ensure timely communication of permission changes.

InnoDB is suitable for applications that require transaction support and high concurrency, while MyISAM is suitable for applications that require more reads and less writes. 1.InnoDB supports transaction and bank-level locks, suitable for e-commerce and banking systems. 2.MyISAM provides fast read and indexing, suitable for blogging and content management systems.

There are four main JOIN types in MySQL: INNERJOIN, LEFTJOIN, RIGHTJOIN and FULLOUTERJOIN. 1.INNERJOIN returns all rows in the two tables that meet the JOIN conditions. 2.LEFTJOIN returns all rows in the left table, even if there are no matching rows in the right table. 3. RIGHTJOIN is contrary to LEFTJOIN and returns all rows in the right table. 4.FULLOUTERJOIN returns all rows in the two tables that meet or do not meet JOIN conditions.

MySQLoffersvariousstorageengines,eachsuitedfordifferentusecases:1)InnoDBisidealforapplicationsneedingACIDcomplianceandhighconcurrency,supportingtransactionsandforeignkeys.2)MyISAMisbestforread-heavyworkloads,lackingtransactionsupport.3)Memoryengineis

Common security vulnerabilities in MySQL include SQL injection, weak passwords, improper permission configuration, and unupdated software. 1. SQL injection can be prevented by using preprocessing statements. 2. Weak passwords can be avoided by forcibly using strong password strategies. 3. Improper permission configuration can be resolved through regular review and adjustment of user permissions. 4. Unupdated software can be patched by regularly checking and updating the MySQL version.

Identifying slow queries in MySQL can be achieved by enabling slow query logs and setting thresholds. 1. Enable slow query logs and set thresholds. 2. View and analyze slow query log files, and use tools such as mysqldumpslow or pt-query-digest for in-depth analysis. 3. Optimizing slow queries can be achieved through index optimization, query rewriting and avoiding the use of SELECT*.


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

Dreamweaver CS6
Visual web development tools

SublimeText3 Chinese version
Chinese version, very easy to use

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

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.

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