我知道如何mysqldump
运作。但是不知道用在哪里?
如果我在启动程序后执行此命令,mysql
则会显示错误。
我正在使用 ubuntu。那么我该如何使用这个实用程序呢?
也以这种方式备份您的数据库..
mysql -u root -p DB_NAME > db_name_backup.sql
如果你想备份所有数据库只需运行这个
mysql -u root -p > mysql_db_backup.sql
您将在此处了解有关 mysql 和 mysqldump 的更多信息。
指南:
mysqldump 和 mysql
使用 mysqldump 备份 MySQL 数据库
外壳> mysqldump --opt db_name > 备份文件.sql
You can read 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
It is possible to dump several databases with one command:
shell> mysqldump --databases db_name1 [db_name2 ...] > my_databases.sql
If you want to dump all databases, use the --all-databases option:
shell> mysqldump --all-databases > all_databases.sql
If tables are stored in the InnoDB storage engine, mysqldump provides a
way of making an online backup of these (see command below). This
backup just needs to acquire a global read lock on all tables (using
FLUSH TABLES WITH READ LOCK) at the beginning of the dump. As soon as
this lock has been acquired, the binary log coordinates are read and
lock is released. So if and only if one long updating statement is
running when the FLUSH... is issued, the MySQL server may get stalled
until that long statement finishes, and then the dump becomes
lock-free. So if the MySQL server receives only short (in the sense of
"short execution time") updating statements, even if there are plenty
of them, the initial lock period should not be noticeable.
shell> mysqldump --all-databases --single-transaction > all_databases.sql
For point-in-time recovery (also known as “roll-forward”, when you need
to restore an old backup and replay the changes which happened since
that backup), it is often useful to rotate the binary log (see
Section 8.4, “The Binary Log”) or at least know the binary log
coordinates to which the dump corresponds:
shell> mysqldump --all-databases --master-data=2 > all_databases.sql
or
shell> mysqldump --all-databases --flush-logs --master-data=2 > all_databases.sql
The simultaneous use of --master-data and --single-transaction works as
of MySQL 4.1.8. It provides a convenient way to make an online backup
suitable for point-in-time recovery if tables are stored in the InnoDB
storage engine.
For more information on making backups, see Section 6.1, “Database
Backups”.
mysqldump -u MYSQL_USER -h MYSQL_SERVER -pMYSQL_PASS --all-databases > "dbs.sql"
您直接在终端上使用它,就像mysql
它自己一样,并将参数直接传递给它。
mysqldump -u [user] -p[password] [database name] > dumpfilename.sql
是的你可以。
有关该工具的更多信息,请参阅http://dev.mysql.com/doc/refman/5.0/en/mysqldump.html。
如果它是一个完整的数据库,那么:
$ mysqldump -u [uname] -p[pass] db_name > db_backup.sql
如果都是数据库,那么:
$ mysqldump -u [uname] -p[pass] --all-databases > all_db_backup.sql
如果它是数据库中的特定表,则:
$ mysqldump -u [uname] -p[pass] db_name table1 table2 > table_backup.sql
您甚至可以使用 gzip 自动压缩输出(如果您的数据库非常大):
$ mysqldump -u [uname] -p[pass] db_name | gzip > db_backup.sql.gz
如果您想远程执行此操作并且您可以访问相关服务器,那么以下操作将起作用(假设 MySQL 服务器位于端口 3306 上):
$ mysqldump -P 3306 -h [ip_address] -u [uname] -p[pass] db_name > db_backup.sql
导入:_
键入以下命令以导入 sql 数据文件:
$ mysql -u 用户名 -p -h localhost DATA-BASE-NAME < data.sql
在此示例中,使用 vivek 作为用户名将“data.sql”文件导入“博客”数据库:
$ mysql -u sat -p -h localhost 博客 < data.sql
如果您有专用的数据库服务器,请将 localhost 主机名替换为实际的服务器名称或 IP 地址,如下所示:
$ mysql -u 用户名 -p -h 202.54.1.10 数据库名 < data.sql
或使用主机名,例如 mysql.cyberciti.biz
$ mysql -u 用户名 -p -h mysql.cyberciti.biz 数据库名称 < data.sql
如果您不知道数据库名称或数据库名称包含在 sql 转储中,您可以尝试如下操作:
$ mysql -u 用户名 -p -h 202.54.1.10 < data.sql
参考: http ://dev.mysql.com/doc/refman/5.6/en/mysqldump.html