将 MySQL 表还原回数据库
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9696249/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Restoring a MySQL table back to the database
提问by Luna
I have a trouble in restoring MySQL table back to the database from command line. Taking backup of a table is working with mysqldump.Taking backup and restoring of a database is also working properly. I have used:
我在从命令行将 MySQL 表恢复回数据库时遇到了麻烦。备份表与 mysqldump 一起工作。备份和恢复数据库也正常工作。我用过了:
mysql -uroot -p DatabaseName TableName < path\TableName.sql
mysql -uroot -p DatabaseName TableName < path\TableName.sql
Thanks in advance
提前致谢
回答by Phil
Ah, I think I see the problem here.
啊,我想我在这里看到了问题。
Your backup script looks fine. tbl_name
works correctly as the optional 2nd argument.
您的备份脚本看起来不错。tbl_name
作为可选的第二个参数正常工作。
To restore, you should simply run
要恢复,您只需运行
mysql -uroot -p DatabaseName < path\TableName.sql
Running man mysql
would have shown you the correct arguments and options
运行man mysql
会向您展示正确的参数和选项
mysql [options] db_name
mysql [选项] db_name
As your backup script only contains one table, only that table will be restored into your database.
由于您的备份脚本仅包含一张表,因此只有该表会恢复到您的数据库中。
回答by Naveen Kumar
Taking backup
采取备份
mysqldump -u -p mydatabase table1 > table1.sql
restoring from backup flie need not include table name
从备份文件中恢复不需要包含表名
mysql -u -p mydatabase < table1.sql
回答by Ranvir
Best way to restore your database:
恢复数据库的最佳方法:
open cmdat bin
folder
在文件夹中打开cmdbin
login to mysql:
登录mysql:
mysql -uroot -pyour_password
show databases;
use db_name;
now hit source and put the complete path from address bar where your sql file is stored and hit ;
现在点击源代码并从地址栏中输入存储您的 sql 文件的完整路径并点击;
for example :
例如 :
source db_name.sql;
回答by edx1
Copy your db.sql file to your Mysql Server if you are in a remote machine:
如果您在远程机器上,请将您的 db.sql 文件复制到您的 Mysql 服务器:
$rsync -Cravzp --progress db.sql [email protected]:/home/user
$rsync -Cravzp --progress db.sql [email protected]:/home/user
Now you can go to your remote server as:
现在您可以通过以下方式访问远程服务器:
$ssh -l user 192.168.10.1
$ssh -l 用户 192.168.10.1
In the Mysql Server you must to do this:
在 Mysql Server 中你必须这样做:
user@machine:~$mysql -h localhost -u root -p
用户@机器:~$ mysql -h localhost -u root -p
Obs: The file db.sql must be in the same place (/home/user).
Obs: 文件 db.sql 必须在同一个地方 (/home/user)。
Now type this command in you Mysql Server:
现在在你的 Mysql Server 中输入这个命令:
mysql>'\'. db.sql+ Enter. Obs: Remove all ' from this command to work
mysql>'\'。db.sql+ 回车。Obs:从此命令中删除所有 ' 以工作