//备份 mysqldump --add-drop-database -h192.168.1.1 -uroot -proot --databases xxxxdb > D:\xxxdb.sql // --databases选项,生成create database语句 //----add-drop-database 生成drop table语句 //导入 mysql -h127.0.0.1 -uroot -proot < D:\xxxdb.sql
mysqldump
引用
mysqldump Ver 10.13 Distrib 5.6.10, for Win64 (x86_64)
Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Dumping structure and contents of MySQL databases and tables.
Usage: mysqldump [OPTIONS] database [tables]
OR mysqldump [OPTIONS] --databases [OPTIONS] DB1 [DB2 DB3...]
OR mysqldump [OPTIONS] --all-databases [OPTIONS]
Default options are read from the following files in the given order:
C:\Windows\my.ini C:\Windows\my.cnf C:\my.ini C:\my.cnf D:\mysql-5.6.10-winx64\my.ini D:\mysql-5.6.10-winx64\my.cnf
The following groups are read: mysqldump client
The following options may be given as the first argument:
--print-defaults Print the program argument list and exit.
--no-defaults Don't read default options from any option file,
except for login file.
--defaults-file=# Only read default options from the given file #.
--defaults-extra-file=# Read this file after the global files are read.
--defaults-group-suffix=#
Also read groups with concat(group, suffix)
--login-path=# Read this path from the login file.
-A, --all-databases Dump all the databases. This will be same as --databases
with all databases selected.
-Y, --all-tablespaces
Dump all the tablespaces.
-y, --no-tablespaces
Do not dump any tablespace information.
--add-drop-database Add a DROP DATABASE before each create.
--add-drop-table Add a DROP TABLE before each create.
(Defaults to on; use --skip-add-drop-table to disable.)
--add-drop-trigger Add a DROP TRIGGER before each create.
--add-locks Add locks around INSERT statements.
(Defaults to on; use --skip-add-locks to disable.)
--allow-keywords Allow creation of column names that are keywords.
--apply-slave-statements
Adds 'STOP SLAVE' prior to 'CHANGE MASTER' and 'START
SLAVE' to bottom of dump.
--bind-address=name IP address to bind to.
--character-sets-dir=name
Directory for character set files.
-i, --comments Write additional information.
(Defaults to on; use --skip-comments to disable.)
--compatible=name Change the dump to be compatible with a given mode. By
default tables are dumped in a format optimized for
MySQL. Legal modes are: ansi, mysql323, mysql40,
postgresql, oracle, mssql, db2, maxdb, no_key_options,
no_table_options, no_field_options. One can use several
modes separated by commas. Note: Requires MySQL server
version 4.1.0 or higher. This option is ignored with
earlier server versions.
--compact Give less verbose output (useful for debugging). Disables
structure comments and header/footer constructs. Enables
options --skip-add-drop-table --skip-add-locks
--skip-comments --skip-disable-keys --skip-set-charset.
-c, --complete-insert
Use complete insert statements.
-C, --compress Use compression in server/client protocol.
-a, --create-options
Include all MySQL specific create options.
(Defaults to on; use --skip-create-options to disable.)
-B, --databases Dump several databases. Note the difference in usage; in
this case no tables are given. All name arguments are
regarded as database names. 'USE db_name;' will be
included in the output.
-#, --debug[=#] This is a non-debug version. Catch this and exit.
--debug-check Check memory and open file usage at exit.
--debug-info Print some debug info at exit.
--default-character-set=name
Set the default character set.
--delayed-insert Insert rows with INSERT DELAYED.
--delete-master-logs
Delete logs on master after backup. This automatically
enables --master-data.
-K, --disable-keys '/*!40000 ALTER TABLE tb_name DISABLE KEYS */; and
'/*!40000 ALTER TABLE tb_name ENABLE KEYS */; will be put
in the output.
(Defaults to on; use --skip-disable-keys to disable.)
--dump-slave[=#] This causes the binary log position and filename of the
master to be appended to the dumped data output. Setting
the value to 1, will printit as a CHANGE MASTER command
in the dumped data output; if equal to 2, that command
will be prefixed with a comment symbol. This option will
turn --lock-all-tables on, unless --single-transaction is
specified too (in which case a global read lock is only
taken a short time at the beginning of the dump - don't
forget to read about --single-transaction below). In all
cases any action on logs will happen at the exact moment
of the dump.Option automatically turns --lock-tables off.
-E, --events Dump events.
-e, --extended-insert
Use multiple-row INSERT syntax that include several
VALUES lists.
(Defaults to on; use --skip-extended-insert to disable.)
--fields-terminated-by=name
Fields in the output file are terminated by the given
string.
--fields-enclosed-by=name
Fields in the output file are enclosed by the given
character.
--fields-optionally-enclosed-by=name
Fields in the output file are optionally enclosed by the
given character.
--fields-escaped-by=name
Fields in the output file are escaped by the given
character.
-F, --flush-logs Flush logs file in server before starting dump. Note that
if you dump many databases at once (using the option
--databases= or --all-databases), the logs will be
flushed for each database dumped. The exception is when
using --lock-all-tables or --master-data: in this case
the logs will be flushed only once, corresponding to the
moment all tables are locked. So if you want your dump
and the log flush to happen at the same exact moment you
should use --lock-all-tables or --master-data with
--flush-logs.
--flush-privileges Emit a FLUSH PRIVILEGES statement after dumping the mysql
database. This option should be used any time the dump
contains the mysql database and any other database that
depends on the data in the mysql database for proper
restore.
-f, --force Continue even if we get an SQL error.
-?, --help Display this help message and exit.
--hex-blob Dump binary strings (BINARY, VARBINARY, BLOB) in
hexadecimal format.
-h, --host=name Connect to host.
--ignore-table=name Do not dump the specified table. To specify more than one
table to ignore, use the directive multiple times, once
for each table. Each table must be specified with both
database and table names, e.g.,
--ignore-table=database.table.
--include-master-host-port
Adds 'MASTER_HOST=<host>, MASTER_PORT=<port>' to 'CHANGE
MASTER TO..' in dump produced with --dump-slave.
--insert-ignore Insert rows with INSERT IGNORE.
--lines-terminated-by=name
Lines in the output file are terminated by the given
string.
-x, --lock-all-tables
Locks all tables across all databases. This is achieved
by taking a global read lock for the duration of the
whole dump. Automatically turns --single-transaction and
--lock-tables off.
-l, --lock-tables Lock all tables for read.
(Defaults to on; use --skip-lock-tables to disable.)
--log-error=name Append warnings and errors to given file.
--master-data[=#] This causes the binary log position and filename to be
appended to the output. If equal to 1, will print it as a
CHANGE MASTER command; if equal to 2, that command will
be prefixed with a comment symbol. This option will turn
--lock-all-tables on, unless --single-transaction is
specified too (in which case a global read lock is only
taken a short time at the beginning of the dump; don't
forget to read about --single-transaction below). In all
cases, any action on logs will happen at the exact moment
of the dump. Option automatically turns --lock-tables
off.
--max-allowed-packet=#
The maximum packet length to send to or receive from
server.
--net-buffer-length=#
The buffer size for TCP/IP and socket communication.
--no-autocommit Wrap tables with autocommit/commit statements.
-n, --no-create-db Suppress the CREATE DATABASE ... IF EXISTS statement that
normally is output for each dumped database if
--all-databases or --databases is given.
-t, --no-create-info
Don't write table creation info.
-d, --no-data No row information.
-N, --no-set-names Same as --skip-set-charset.
--opt Same as --add-drop-table, --add-locks, --create-options,
--quick, --extended-insert, --lock-tables, --set-charset,
and --disable-keys. Enabled by default, disable with
--skip-opt.
--order-by-primary Sorts each table's rows by primary key, or first unique
key, if such a key exists. Useful when dumping a MyISAM
table to be loaded into an InnoDB table, but will make
the dump itself take considerably longer.
-p, --password[=name]
Password to use when connecting to server. If password is
not given it's solicited on the tty.
-W, --pipe Use named pipes to connect to server.
-P, --port=# Port number to use for connection.
--protocol=name The protocol to use for connection (tcp, socket, pipe,
memory).
-q, --quick Don't buffer query, dump directly to stdout.
(Defaults to on; use --skip-quick to disable.)
-Q, --quote-names Quote table and column names with backticks (`).
(Defaults to on; use --skip-quote-names to disable.)
--replace Use REPLACE INTO instead of INSERT INTO.
-r, --result-file=name
Direct output to a given file. This option should be used
in systems (e.g., DOS, Windows) that use carriage-return
linefeed pairs (\r\n) to separate text lines. This option
ensures that only a single newline is used.
-R, --routines Dump stored routines (functions and procedures).
--set-charset Add 'SET NAMES default_character_set' to the output.
(Defaults to on; use --skip-set-charset to disable.)
--set-gtid-purged[=name]
Add 'SET @@GLOBAL.GTID_PURGED' to the output. Possible
values for this option are ON, OFF and AUTO. If ON is
used and GTIDs are not enabled on the server, an error is
generated. If OFF is used, this option does nothing. If
AUTO is used and GTIDs are enabled on the server, 'SET
@@GLOBAL.GTID_PURGED' is added to the output. If GTIDs
are disabled, AUTO does nothing. Default is AUTO.
--shared-memory-base-name=name
Base name of shared memory.
--single-transaction
Creates a consistent snapshot by dumping all tables in a
single transaction. Works ONLY for tables stored in
storage engines which support multiversioning (currently
only InnoDB does); the dump is NOT guaranteed to be
consistent for other storage engines. While a
--single-transaction dump is in process, to ensure a
valid dump file (correct table contents and binary log
position), no other connection should use the following
statements: ALTER TABLE, DROP TABLE, RENAME TABLE,
TRUNCATE TABLE, as consistent snapshot is not isolated
from them. Option automatically turns off --lock-tables.
--dump-date Put a dump date to the end of the output.
(Defaults to on; use --skip-dump-date to disable.)
--skip-opt Disable --opt. Disables --add-drop-table, --add-locks,
--create-options, --quick, --extended-insert,
--lock-tables, --set-charset, and --disable-keys.
-S, --socket=name The socket file to use for connection.
--ssl Enable SSL for connection (automatically enabled with
other flags).
--ssl-ca=name CA file in PEM format (check OpenSSL docs, implies
--ssl).
--ssl-capath=name CA directory (check OpenSSL docs, implies --ssl).
--ssl-cert=name X509 cert in PEM format (implies --ssl).
--ssl-cipher=name SSL cipher to use (implies --ssl).
--ssl-key=name X509 key in PEM format (implies --ssl).
--ssl-crl=name Certificate revocation list (implies --ssl).
--ssl-crlpath=name Certificate revocation list path (implies --ssl).
--ssl-verify-server-cert
Verify server's "Common Name" in its cert against
hostname used when connecting. This option is disabled by
default.
-T, --tab=name Create tab-separated textfile for each table to given
path. (Create .sql and .txt files.) NOTE: This only works
if mysqldump is run on the same machine as the mysqld
server.
--tables Overrides option --databases (-B).
--triggers Dump triggers for each dumped table.
(Defaults to on; use --skip-triggers to disable.)
--tz-utc SET TIME_ZONE='+00:00' at top of dump to allow dumping of
TIMESTAMP data when a server has data in different time
zones or data is being moved between servers with
different time zones.
(Defaults to on; use --skip-tz-utc to disable.)
-u, --user=name User for login if not current user.
-v, --verbose Print info about the various stages.
-V, --version Output version information and exit.
-w, --where=name Dump only selected records. Quotes are mandatory.
-X, --xml Dump a database as well formed XML.
--plugin-dir=name Directory for client-side plugins.
--default-auth=name Default authentication client-side plugin to use.
Variables (--variable-name=value)
and boolean options {FALSE|TRUE} Value (after reading options)
--------------------------------- ----------------------------------------
all-databases FALSE
all-tablespaces FALSE
no-tablespaces FALSE
add-drop-database FALSE
add-drop-table TRUE
add-drop-trigger FALSE
add-locks TRUE
allow-keywords FALSE
apply-slave-statements FALSE
bind-address (No default value)
character-sets-dir (No default value)
comments TRUE
compatible (No default value)
compact FALSE
complete-insert FALSE
compress FALSE
create-options TRUE
databases FALSE
debug-check FALSE
debug-info FALSE
default-character-set utf8
delayed-insert FALSE
delete-master-logs FALSE
disable-keys TRUE
dump-slave 0
events FALSE
extended-insert TRUE
fields-terminated-by (No default value)
fields-enclosed-by (No default value)
fields-optionally-enclosed-by (No default value)
fields-escaped-by (No default value)
flush-logs FALSE
flush-privileges FALSE
force FALSE
hex-blob FALSE
host (No default value)
include-master-host-port FALSE
insert-ignore FALSE
lines-terminated-by (No default value)
lock-all-tables FALSE
lock-tables TRUE
log-error (No default value)
master-data 0
max-allowed-packet 25165824
net-buffer-length 1046528
no-autocommit FALSE
no-create-db FALSE
no-create-info FALSE
no-data FALSE
order-by-primary FALSE
port 0
quick TRUE
quote-names TRUE
replace FALSE
routines FALSE
set-charset TRUE
shared-memory-base-name (No default value)
single-transaction FALSE
dump-date TRUE
socket (No default value)
ssl FALSE
ssl-ca (No default value)
ssl-capath (No default value)
ssl-cert (No default value)
ssl-cipher (No default value)
ssl-key (No default value)
ssl-crl (No default value)
ssl-crlpath (No default value)
ssl-verify-server-cert FALSE
tab (No default value)
triggers TRUE
tz-utc TRUE
user (No default value)
verbose FALSE
where (No default value)
plugin-dir (No default value)
default-auth (No default value)
A common use of mysqldump is for making a backup of an entire database:
shell> mysqldump db_name > backup-file.sql
You can load the dump file back into the server like this:
shell> mysql db_name < backup-file.sql
Or like this:
shell> mysql -e "source /path-to-backup/backup-file.sql" db_name
mysqldump is also very useful for populating databases by copying data from one MySQL server to another:
shell> mysqldump --opt db_name | mysql --host=remote_host -C db_name
mysql 命令
引用
mysql is a simple SQL shell with input line editing capabilities. It supports interactive and noninteractive use. When used interactively, query results are presented in an ASCII-table format. When used noninteractively (for example, as a filter), the result is presented in tab-separated format. The output format can be changed using command options.
If you have problems due to insufficient memory for large result sets, use the --quick option. This forces mysql to retrieve results from the server a row at a time rather than retrieving the entire result set and buffering it in memory before displaying it. This is done by returning the result set using the mysql_use_result() C API function in the client/server library rather than mysql_store_result().
Using mysql is very easy. Invoke it from the prompt of your command interpreter as follows:
shell> mysql db_name
Or:
shell> mysql --user=user_name --password=your_password db_name
Then type an SQL statement, end it with “;”, \g, or \G and press Enter.
As of MySQL 5.1.10, typing Control+C causes mysql to attempt to kill the current statement. If this cannot be done, or Control+C is typed again before the statement is killed, mysql exits. Previously, Control+C caused mysql to exit in all cases.
You can execute SQL statements in a script file (batch file) like this:
shell> mysql db_name < script.sql > output.tab
On Unix, the mysql client logs statements executed interactively to a history file. See Section 4.5.1.3, “mysql Logging”.
mysql 测试语句
SELECT NOW(); mysql -uroot -proot -e "use mydb;select * from sometable;"
发表评论
-
linux 安装mysql多个实例
2020-03-13 15:47 426mysql5.7.28多实例 安装mysql,不要启动 创 ... -
mongodb安全验证 密码登录
2020-03-09 16:07 8381、创建用户 cd /d C:\Program Files\ ... -
索引的创建对查询性能影响
2019-08-19 15:14 685索引的正确使用,对查询的性能影响很大 原查询,要2分多 ... -
mysql查询性能优化,650秒优化到0.18秒
2019-08-14 17:57 29开发人员技术水平不一,写出的sql执行性能怎么样,完全靠运气, ... -
MySQL 高可用集群架构 MHA 详解
2018-03-09 09:28 801MySQL 高可用集群架构 MHA ... -
B+tree 索引
2018-03-09 09:11 752mysql和oracle都用到B+tree ... -
怎么查看和修改 MySQL 的最大连接数
2018-03-09 08:47 1122通常,mysql的最大连接数默认是100, 最大可以达到163 ... -
mysql 删除重复记录 保留一条
2018-01-25 10:47 1173-- 方法一 /** 错误码: 1093 You ... -
rsync备份和删除指定文件
2018-01-02 10:23 2060文件异地备份时,需要将本地文件合并到服务器上,且不能删除服务器 ... -
windows mysql定时备份任务
2017-11-03 16:12 1007mysqlbak.cmd echo off set tx ... -
mysql 1418错误原因及解决
2017-09-30 11:14 1141SET GLOBAL log_bin_trust_functi ... -
windows上oracle11配置监听器
2017-08-23 14:00 1778oracle11 windows版安装后默认通过计算机名 ... -
centos yum 安装mysql
2016-08-11 10:08 532查看这篇文章 http://dev.mysql.com/dow ... -
expdp\impdp及exp\imp
2016-08-03 14:29 765作者写的文章很实用 ht ... -
oracle drop记录
2016-07-21 14:07 1592数据库中缺表了,查一下是什么时候删除的 select * ... -
powerdesigner 16 从数据库生成表结构无响应
2016-07-15 09:35 1335怪事了,powerdesigner从数据库反向生成表结构是,卡 ... -
oracle 删除和重建表空间脚本
2016-07-07 11:23 2612调试数据库生成脚本,需要频繁重建表空间 /** ... -
plsql11 x64 安装和配置 解决OCI: not initialized
2016-06-18 09:38 16964下载了instantclient-basic-windows. ... -
oracle instantclient和plsql配置
2016-05-23 14:47 7431、下载instantclient 下载后多解压到某文件夹下 ... -
oracle AL32UTF8 zhs16gbk 安装字符编码
2016-05-23 14:30 1563NLS_LANG是环境变量,包括3部分NLS参数:NLS_LA ...
相关推荐
MySQL数据库备份和导入使用SQLyog MySQL数据库备份和导入是数据库管理员和开发者经常需要执行的任务。为了将数据库备份到安全的位置,以防止数据丢失,并且在需要时可以将其恢复到原来的状态。本文将介绍如何使用...
以上内容介绍了如何通过Java程序实现MySQL数据库的自动备份和自动导入功能。这种方式不仅能够提高数据安全性,还能减少人工操作带来的错误风险。需要注意的是,在实际应用中还需要考虑异常处理机制,确保程序的健壮...
#### MySQL备份的重要性 备份是数据管理中最基础也是最重要的一环。它不仅能够防止数据丢失,还能在数据库遭遇故障时迅速恢复服务,避免业务中断造成的损失。此外,定期的数据库备份还能帮助组织满足合规性要求,...
一个mysql数据备份类。直接换上数据库底部换上数据库的连接方式直接运行即可。
MySQL 数据库备份和恢复详解 MySQL 数据库是当今最流行的关系数据库管理系统之一,对于数据的备份和恢复至关重要。本文将详细介绍 MySQL 数据库的备份和恢复方法,以便更好地保护数据安全。 一、MySQL 数据库备份 ...
### 如何导入超大MySQL数据库备份文件 #### BigDump工具简介及应用场景 在日常网站管理和维护过程中,数据库的备份和恢复是一项重要的工作。常见的MySQL数据库管理工具如phpMyAdmin因其直观的操作界面和丰富的功能...
MySQL的备份和恢复是数据库管理的关键环节,确保数据的...总的来说,MySQL备份和恢复需要根据不同的表类型和需求选择合适的工具和策略。定期备份、测试恢复过程以及了解备份参数的正确使用是保证数据安全的关键步骤。
一、MySQL备份的重要性 数据库备份是防止数据丢失的关键步骤。无论是系统故障、硬件损坏、恶意攻击还是人为错误,都有可能导致数据丢失。定期备份可以确保在灾难发生时,能够快速恢复到正常状态,降低业务中断的影响...
在UNIX环境下,MySQL数据库的备份和恢复是数据库管理...总之,UNIX环境下的MySQL备份和恢复需要根据表类型选择合适的工具和策略。理解并熟练运用这些工具的参数和选项,能有效确保数据安全,同时提高备份和恢复的效率。
"mysql备份.zip"这个压缩包提供了在Windows和Linux操作系统上进行MySQL数据库自动备份的解决方案。 在Windows环境下,"db.bat"是一个批处理文件,用于执行MySQL的备份任务。批处理文件通常包含一系列命令,这里可能...
MySQL 数据备份和还原的常用命令 MySQL 数据备份和还原是数据库管理中非常重要的一步,能够防止数据丢失和恢复数据库。下面将介绍 MySQL 数据备份和还原的常用命令。 MySQL 数据备份命令 1. 备份 MySQL 数据库的...
本篇文章将深入探讨如何使用PHP来实现MySQL数据库的备份和导入功能,以满足那些不熟悉数据库操作的用户需求。 首先,我们需要了解的是PHP是如何与MySQL进行交互的。PHP提供了多种方式来连接和操作MySQL数据库,如...
在数据库管理和维护中,数据导入和导出是非常关键的操作,尤其是在MySQL数据库管理系统中。数据导入导出的目的多种多样,比如数据备份、数据迁移、数据整合等,因此掌握高效可靠的数据导入导出方法对于数据库管理员...
根据提供的实验报告“MYSQL备份与恢复”的相关内容,我们可以总结出以下几个关键知识点: ### 一、MYSQL日志管理 #### 1. 错误日志 - **定义**: 记录MySQL运行过程中的错误信息和警告信息。 - **作用**: 帮助管理...
阿里云 RDS for MySQL 的备份策略分为两种:物理备份和逻辑备份。物理备份使用 Percona Xtrabackup 工具对物理层存储文件进行备份,是一种物理级的备份操作,因此备份速度较快,但是移植性(兼容性)较差。逻辑备份...
总的来说,这个JAVA工具类提供了对MySQL和Oracle数据库的备份和导入功能,通过集成常见的数据库备份工具,简化了开发人员的工作流程。在实际使用时,需要根据具体环境配置相关参数,并注意处理可能出现的各种异常...
`mysqldump` 是 MySQL 提供的一个非常强大的工具,用于备份和恢复整个数据库或单个表的数据。 ##### 备份数据库 1. **备份整个数据库**: ```bash mysqldump -h hostname -u username -p password database_name ...