mysql mysqldump用于主主(主从)复制(不加锁,不影响业务)

3 篇文章 0 订阅
本文详细介绍了如何使用mysqldump进行主主复制,包括备份主库、在从库加载数据、修改从库的log位置以及启动和检查slave状态。同时,解析了mysqldump的关键参数,如--master-data、--add-drop-database和--add-drop-table等,这些参数在数据库备份和主从复制中起到重要作用。
摘要由CSDN通过智能技术生成

mysqldump用于主主(主从)复制(不加锁,不影响业务)

操作

1.备份主库数据

mysqldump  -uroot -pR1234qwroot -F --master-data=2 -A --add-drop-database --add-drop-table > all.sql

2.从库加载数据

source /home/odcp/all.sql

3.从库修改log位置

#查看MASTER_LOG_FILE
head -30 all.sql

在这里插入图片描述

change master to master_host='10.1.234.110',master_user='repuser',master_password='repuser',master_port=3306;
CHANGE MASTER TO MASTER_LOG_FILE='mysql-bin.000202',MASTER_LOG_POS=154;

4.启动slave

start slave;

5.查看slave

show slave status\G

在这里插入图片描述

mysqldump参数解释

-A :所有库;
-F:刷新logs
–add-drop-database:在每个 CREATE DATABASE 语句之前添加 DROP DATABASE 语句
–add-drop-table 在每个 CREATE TABLE 语句之前添加 DROP TABLE 语句
–master-data:

Use this option to dump a master replication server to produce a dump file that can be used to set up another server as a slave of the master.
It causes the dump output to include a CHANGE MASTER TO statement that indicates the binary log coordinates (file name and position) of the dumped server.

These are the master server coordinates from which the slave should start replicating after you load the dump file into the slave.

使用此选项dump a master replication server到dump文件,可用于设立另一台服务器作为master的slave。

它会使dump输出包含CHANGE MASTER TO语句,标记dump源的二进制日志坐标(文件名和位置)。

在把load dump文件加载到slave之后,slave应当从该master坐标开始复制。
更多master-data参考

mysqldump官网参数

参数描述介绍
–add-drop-databaseAdd DROP DATABASE statement before each CREATE DATABASE statement
–add-drop-tableAdd DROP TABLE statement before each CREATE TABLE statement
–add-drop-triggerAdd DROP TRIGGER statement before each CREATE TRIGGER statement
–add-locksSurround each table dump with LOCK TABLES and UNLOCK TABLES statements
–all-databasesDump all tables in all databases
–allow-keywordsAllow creation of column names that are keywords
–apply-slave-statementsInclude STOP SLAVE prior to CHANGE MASTER statement and START SLAVE at end of output
–bind-addressUse specified network interface to connect to MySQL Server
–character-sets-dirDirectory where character sets are installed
–commentsAdd comments to dump file
–compactProduce more compact output
–compatibleProduce output that is more compatible with other database systems or with older MySQL servers
–complete-insertUse complete INSERT statements that include column names
–compressCompress all information sent between client and server
–create-optionsInclude all MySQL-specific table options in CREATE TABLE statements
–databasesInterpret all name arguments as database names
–debugWrite debugging log
–debug-checkPrint debugging information when program exits
–debug-infoPrint debugging information, memory, and CPU statistics when program exits
–default-authAuthentication plugin to use
–default-character-setSpecify default character set
–defaults-extra-fileRead named option file in addition to usual option files
–defaults-fileRead only named option file
–defaults-group-suffixOption group suffix value
–delete-master-logsOn a replication source server, delete the binary logs after performing the dump operation
–disable-keysFor each table, surround INSERT statements with statements to disable and enable keys
–dump-dateInclude dump date as “Dump completed on” comment if --comments is given
–dump-slaveInclude CHANGE MASTER statement that lists binary log coordinates of replica’s source
–enable-cleartext-pluginEnable cleartext authentication plugin5.7.10
–eventsDump events from dumped databases
–extended-insertUse multiple-row INSERT syntax
–fields-enclosed-byThis option is used with the --tab option and has the same meaning as the corresponding clause for LOAD DATA
–fields-escaped-byThis option is used with the --tab option and has the same meaning as the corresponding clause for LOAD DATA
–fields-optionally-enclosed-byThis option is used with the --tab option and has the same meaning as the corresponding clause for LOAD DATA
–fields-terminated-byThis option is used with the --tab option and has the same meaning as the corresponding clause for LOAD DATA
–flush-logsFlush MySQL server log files before starting dump
–flush-privilegesEmit a FLUSH PRIVILEGES statement after dumping mysql database
–forceContinue even if an SQL error occurs during a table dump
–get-server-public-keyRequest RSA public key from server5.7.23
–helpDisplay help message and exit
–hex-blobDump binary columns using hexadecimal notation
–hostHost on which MySQL server is located
–ignore-errorIgnore specified errors
–ignore-tableDo not dump given table
–include-master-host-portInclude MASTER_HOST/MASTER_PORT options in CHANGE MASTER statement produced with --dump-slave
–insert-ignoreWrite INSERT IGNORE rather than INSERT statements
–lines-terminated-byThis option is used with the --tab option and has the same meaning as the corresponding clause for LOAD DATA
–lock-all-tablesLock all tables across all databases
–lock-tablesLock all tables before dumping them
–log-errorAppend warnings and errors to named file
–login-pathRead login path options from .mylogin.cnf
–master-dataWrite the binary log file name and position to the output
–max-allowed-packetMaximum packet length to send to or receive from server
–net-buffer-lengthBuffer size for TCP/IP and socket communication
–no-autocommitEnclose the INSERT statements for each dumped table within SET autocommit = 0 and COMMIT statements
–no-create-dbDo not write CREATE DATABASE statements
–no-create-infoDo not write CREATE TABLE statements that re-create each dumped table
–no-dataDo not dump table contents
–no-defaultsRead no option files
–no-set-namesSame as --skip-set-charset
–no-tablespacesDo not write any CREATE LOGFILE GROUP or CREATE TABLESPACE statements in output
–optShorthand for --add-drop-table --add-locks --create-options --disable-keys --extended-insert --lock-tables --quick --set-charset
–order-by-primaryDump each table’s rows sorted by its primary key, or by its first unique index
–passwordPassword to use when connecting to server
–pipeConnect to server using named pipe (Windows only)
–plugin-dirDirectory where plugins are installed
–portTCP/IP port number for connection
–print-defaultsPrint default options
–protocolTransport protocol to use
–quickRetrieve rows for a table from the server a row at a time
–quote-namesQuote identifiers within backtick characters
–replaceWrite REPLACE statements rather than INSERT statements
–result-fileDirect output to a given file
–routinesDump stored routines (procedures and functions) from dumped databases
–secure-authDo not send passwords to server in old (pre-4.1) format
–server-public-key-pathPath name to file containing RSA public key5.7.23
–set-charsetAdd SET NAMES default_character_set to output
–set-gtid-purgedWhether to add SET @@GLOBAL.GTID_PURGED to output
–shared-memory-base-nameShared-memory name for shared-memory connections (Windows only)
–single-transactionIssue a BEGIN SQL statement before dumping data from server
–skip-add-drop-tableDo not add a DROP TABLE statement before each CREATE TABLE statement
–skip-add-locksDo not add locks
–skip-commentsDo not add comments to dump file
–skip-compactDo not produce more compact output
–skip-disable-keysDo not disable keys
–skip-extended-insertTurn off extended-insert
–skip-mysql-schemaDo not drop the mysql schema5.7.36
–skip-optTurn off options set by --opt
–skip-quickDo not retrieve rows for a table from the server a row at a time
–skip-quote-namesDo not quote identifiers
–skip-set-charsetDo not write SET NAMES statement
–skip-triggersDo not dump triggers
–skip-tz-utcTurn off tz-utc
–socketUnix socket file or Windows named pipe to use
–sslEnable connection encryption
–ssl-caFile that contains list of trusted SSL Certificate Authorities
–ssl-capathDirectory that contains trusted SSL Certificate Authority certificate files
–ssl-certFile that contains X.509 certificate
–ssl-cipherPermissible ciphers for connection encryption
–ssl-crlFile that contains certificate revocation lists
–ssl-crlpathDirectory that contains certificate revocation-list files
–ssl-keyFile that contains X.509 key
–ssl-modeDesired security state of connection to server5.7.11
–ssl-verify-server-certVerify host name against server certificate Common Name identity
–tabProduce tab-separated data files
–tablesOverride --databases or -B option
–tls-versionPermissible TLS protocols for encrypted connections5.7.10
–triggersDump triggers for each dumped table
–tz-utcAdd SET TIME_ZONE=‘+00:00’ to dump file
–userMySQL user name to use when connecting to server
–verboseVerbose mode
–versionDisplay version information and exit
–whereDump only rows selected by given WHERE condition
–xmlProduce XML output

更多参考

主主同步配置

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值