简体   繁体   English

将 MySQL 表还原回数据库

[英]Restoring a MySQL table back to the database

I have a trouble in restoring MySQL table back to the database from command line.我在从命令行将 MySQL 表恢复回数据库时遇到了麻烦。 Taking backup of a table is working with mysqldump.Taking backup and restoring of a database is also working properly.备份表与 mysqldump 一起工作。备份和恢复数据库也正常工作。 I have used:我用过了:

mysql -uroot -p DatabaseName TableName < path\\TableName.sql mysql -uroot -p DatabaseName TableName < path\\TableName.sql

Thanks in advance提前致谢

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.由于您的备份脚本仅包含一张表,因此只有该表会恢复到您的数据库中。

Taking backup采取备份

mysqldump -u -p mydatabase table1 > database_dump.sql

restoring from backup flie need not include table name从备份文件中恢复不需要包含表名

mysql -u -p mydatabase < database_dump.sql

Best way to restore your database:恢复数据库的最佳方法:

open cmd at bin folderbin文件夹中打开cmd

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;

Copy your db.sql file to your Mysql Server if you are in a remote machine:如果您在远程机器上,请将您的 db.sql 文件复制到您的 Mysql 服务器:

$rsync -Cravzp --progress db.sql user@192.168.10.1:/home/user $rsync -Cravzp --progress db.sql user@192.168.10.1:/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>'\\'. mysql>'\\'。 db.sql + Enter. db.sql + 回车。 Obs: Remove all ' from this command to work Obs:从此命令中删除所有 ' 以工作

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM