mysql 备份表无法恢复_Mysql 备份与恢复 mysqldump

ec05cbb0de861eb447a1b90f3e765ff2.png

mysqldump 是 Mysql 逻辑备份的 Mysql 客户端工具,用于生成一组SQL语句,通过执行这些生成的SQL语句来重现原始的数据库对象定义和表数据。可以对一个或多个MySQL数据库进行备份或转移到另一个数据库服务器。mysqldump命令还可以生成CSV、其他分隔符文本或XML格式的数据文件。

默认不带参数的导出,导出SQL文件内容大概如下:

shell> mysqldump [ options ] db_name [ tbl_name . . . ] # 备份数据库下面的一个或多个表 shell> mysqldump [ options ] --databases db_name . . . # 备份一个或多个数据库 shell> mysqldump [ options ] --all-databases # 全库备份 mysqldump 可选的 Options:
Option 名称描述
--add-drop-database在创建数据库命令之前增加删除数据库命令
--add-drop-table在创建表之前增加删除表命令
--add-drop-trigger在创建触发器之前踢增加删除触发期命令
--add-locks在导出表时锁定表,完成后解锁
--all-databases

出数据库服务器中全部数据库和表

--allow-keywords

允许创建关键词的列名字。

--apply-slave-statements集群导出时增加开启和关闭slave命令
--bind-address使用特定的IP连接数据库
--character-sets-dir字符集所在目录
--column-statistics添加 ANALYZE TABLE 命令
--comments导出表注释
--compact紧凑输出
--compatible生成兼容性导出文件
--complete-insert生成包含字段名的插入语句
--compress启用压缩
--compression-algorithms压缩算法
--create-options

在CREATE TABLE语句中包括所有MySQL特性选项。(默认为打开状态)

--databases数据库名称
--debug输出debug log
--debug-check

检查内存和打开文件使用说明并退出。

--debug-info

输出调试信息并退出,包括内存,CPU统计信息

--default-auth默认验证方式
--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 master replication 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 slave's master
--enable-cleartext-pluginEnable cleartext authentication plugin
--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 server
--helpDisplay help message and exit
--hex-blobDump binary columns using hexadecimal notation
--host数据库所在地址,远程导出时指定地址
--ignore-error忽略特定错误
--ignore-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
--network-timeoutIncrease network timeouts to permit larger table dumps
--no-autocommitEnclose the INSERT statements for each dumped table within SET autocommit = 0 and COMMIT statements
--no-create-db禁止生成创建database 语句
--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
--opt一系列默认的参数,包括:
--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
--password数据库访问密码
--pipeConnect to server using named pipe (Windows only)
--plugin-dirDirectory where plugins are installed
--port数据库指定端口
--print-defaultsPrint default options
--protocolConnection 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
--server-public-key-pathPath name to file containing RSA public key
--set-charsetAdd SET NAMES default_character_set to output
--set-gtid-purgedWhether to add SET @@GLOBAL.GTID_PURGED to output
--shared-memory-base-nameName of shared memory to use for shared-memory connections
--show-create-skip-secondary-engineExclude SECONDARY ENGINE clause from CREATE TABLE statements
--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-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
--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-fips-modeWhether to enable FIPS mode on client side
--ssl-keyFile that contains X.509 key
--ssl-modeDesired security state of connection to server
--tabProduce tab-separated data files
--tablesOverride --databases or -B option
--tls-ciphersuitesPermissible TLSv1.3 ciphersuites for encrypted connections
--tls-versionPermissible TLS protocols for encrypted connections
--triggersDump triggers for each dumped table
--tz-utcAdd SET TIME_ZONE='+00:00' to dump file
--user数据库登陆用户名
--verbose导出时显示详细信息
--versionDisplay version information and exit
--whereDump only rows selected by given WHERE condition
--xmlProduce XML output
--zstd-compression-levelCompression level for connections to server that use zstd compression

几个简单的例子:
1. 指定数据库备份到某dump文件(转储文件)中:
mysqldump -uroot -p123 test > test.dump2.指定远程数据库备份到某dump文件(转储文件)中
mysqldump --host=host1 --opt sourceDb

3.从备份文件恢复数据库

mysql [database name] < [backup file name]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值