mysql数据库备份

一、mysqldump导出数据

1、导出数据库表结构

 mysqldump  -uroot -proot  -d  test_db >  /home/test_db.sql

2、到出数据库表数据

mysqldump  -uroot -proot  -t   test_db >  /home/test_db.sql

3、导出数据库表结构和数据

 mysqldump  -uroot -proot   test_db >  /home/test_db.sql

4、导出单表结构

mysqldump -uroot -proot --set-gtid-purged=OFF -d test_db  t_user>'/home/t_user.sql'

5、导出单表数据

mysqldump  -uroot -proot  -t  test_db  t_user>/home/t_user.sql

6、导出单表结构和数据

mysqldump -uroot -proot --set-gtid-purged=OFF test_db  t_user>'/home/sys_user.sql'

、select导出数据

  1、secure_file_priv

   查看secure_file_priv是否允许把数据导出到任何目录

SHOW  VARIABLES  LIKE	  '%secure_file_priv%';

    如果为NULL,则在my.cnf配置文件中配置想要导出的的目录即可

  2、导出表数据


 SELECT  * FROM  t_user INTO OUTFILE '/var/lib/mysql-files/t_user.sql';

 

 导入数据

1、方式一:load data

LOAD DATA LOCAL INFILE '/var/lib/mysql-files/t_user.sql' INTO TABLE t_user  LINES TERMINATED BY '\r\n';

2、方式二:mysql   

mysql -uroot -p test_db  < t_user.sql

3、方式三:insert into 

INSERT  INTO   t_user_back(id,name)  SELECT  id,name  FROM  t_user;

 

四、mysqldump参数

Option NameDescriptionIntroducedDeprecated
--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-replica-statementsInclude STOP REPLICA prior to CHANGE REPLICATION SOURCE TO statement and START REPLICA at end of output8.0.26
--apply-slave-statementsInclude STOP SLAVE prior to CHANGE MASTER statement and START SLAVE at end of output8.0.26
--bind-addressUse specified network interface to connect to MySQL Server
--character-sets-dirDirectory where character sets are installed
--column-statisticsWrite ANALYZE TABLE statements to generate statistics histograms
--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 server8.0.18
--compression-algorithmsPermitted compression algorithms for connections to server8.0.18
--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 operation8.0.26
--delete-source-logsOn a replication source server, delete the binary logs after performing the dump operation8.0.26
--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-replicaInclude CHANGE REPLICATION SOURCE TO statement that lists binary log coordinates of replica's source8.0.26
--dump-slaveInclude CHANGE MASTER statement that lists binary log coordinates of replica's source8.0.26
--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
--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-slave8.0.26
--include-source-host-portInclude SOURCE_HOST and SOURCE_PORT options in CHANGE REPLICATION SOURCE TO statement produced with --dump-replica8.0.26
--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 output8.0.26
--max-allowed-packetMaximum packet length to send to or receive from server
--mysqld-long-query-timeSession value for slow query threshold8.0.30
--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-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
--password1First multifactor authentication password to use when connecting to server8.0.27
--password2Second multifactor authentication password to use when connecting to server8.0.27
--password3Third multifactor authentication password to use when connecting to server8.0.27
--pipeConnect to server using named pipe (Windows only)
--plugin-authentication-kerberos-client-modePermit GSSAPI pluggable authentication through the MIT Kerberos library on Windows8.0.32
--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
--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-nameShared-memory name for shared-memory connections (Windows only)
--show-create-skip-secondary-engineExclude SECONDARY ENGINE clause from CREATE TABLE statements8.0.18
--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-generated-invisible-primary-keyDo not include generated invisible primary keys in dump file8.0.30
--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
--source-dataWrite the binary log file name and position to the output8.0.26
--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 side8.0.34
--ssl-keyFile that contains X.509 key
--ssl-modeDesired security state of connection to server
--ssl-session-dataFile that contains SSL session data8.0.29
--ssl-session-data-continue-on-failed-reuseWhether to establish connections if session reuse fails8.0.29
--tabProduce tab-separated data files
--tablesOverride --databases or -B option
--tls-ciphersuitesPermissible TLSv1.3 ciphersuites for encrypted connections8.0.16
--tls-versionPermissible TLS protocols for encrypted connections
--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
--zstd-compression-levelCompression level for connections to server that use zstd compression8.0.18
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值