从命令行下载 MySQL 转储
我要离开 Linode,因为我没有必要的 Linux 系统管理员技能;在我完成向对新手更友好的服务的过渡之前,我需要下载 MySQL 数据库的内容.有没有办法从命令行执行此操作?
I am moving away from Linode because I don't have the Linux sysadmin skills necessary; before I complete the transition to a more noob-friendly service, I need to download the contents of a MySQL database. Is there a way I can do this from the command line?
推荐答案
您可以使用 mysqldump 命令行函数.
You can accomplish this using the mysqldump command-line function.
例如:
如果是整个数据库,则:
If it's an entire DB, then:
$ mysqldump -u [uname] -p db_name > db_backup.sql
如果都是数据库,那么:
If it's all DBs, then:
$ mysqldump -u [uname] -p --all-databases > all_db_backup.sql
如果是数据库中的特定表,则:
If it's specific tables within a DB, then:
$ mysqldump -u [uname] -p db_name table1 table2 > table_backup.sql
您甚至可以使用 gzip 自动压缩输出(如果您的数据库非常大):
You can even go as far as auto-compressing the output using gzip (if your DB is very big):
$ mysqldump -u [uname] -p db_name | gzip > db_backup.sql.gz
如果您想远程执行此操作,并且您可以访问相关服务器,那么以下操作将起作用(假设 MySQL 服务器在端口 3306 上):
If you want to do this remotely and you have the access to the server in question, then the following would work (presuming the MySQL server is on port 3306):
$ mysqldump -P 3306 -h [ip_address] -u [uname] -p db_name > db_backup.sql
它应该将 .sql
文件放到运行命令行的文件夹中.
It should drop the .sql
file in the folder you run the command-line from.
已更新以避免在 CLI 命令中包含密码,请使用不带密码的 -p
选项.它会提示您输入,而不是记录.
Updated to avoid inclusion of passwords in CLI commands, use the -p
option without the password. It will prompt you for it and not record it.
相关文章