[英]mysql, dump, database restore
I have dumped my database with the following command: 我使用以下命令转储了我的数据库:
mysqldump -uuser -ppassword db_name > file
then I completely removed my database: 然后我完全删除了我的数据库:
drop database db_name;
then I created a new database: 然后我创建了一个新的数据库:
create database db_name;
and then I tried to restore the db with the following command: 然后我尝试使用以下命令恢复数据库:
mysqldump -uuser -ppassword db_name < file
The problem is that dump does not create tables and loads data in them and so the database remains empty however it does show a message like dump completed "date time" 问题是转储不会创建表并在其中加载数据,因此数据库保持为空,但它确实显示像dump完成的消息“date time”
What could be the reason for this? 这可能是什么原因?
mysqldump is for dumping the database. mysqldump用于转储数据库。 You've created a new empty database, and then dumped that empty database. 您已经创建了一个新的空数据库,然后转储该空数据库。 Use mysql
instead to reload your dump 请使用mysql
重新加载转储
mysqldump db > dump.sql
mysql drop/create
mysql db < dump.sql
would be the basic command sequence. 将是基本的命令序列。
I like to do the following to restore. 我喜欢做以下恢复。
mysql -uuser -ppassword
create database db;
use db;
source dump.sql;
I tried dump of my database with the following commands: 我尝试使用以下命令转储我的数据库:
#mysqldump -u <username> -p <password> DB_name > <filename>.sql
Then login into the DB: 然后登录到DB:
#mysql -u <username> -p <password>
>show databases;
>drop database <DB_name>;
Then create a new database: 然后创建一个新数据库:
#create database <DB_name>;
DB_name is userdefined name we can have any name. DB_name是用户定义的名称,我们可以有任何名称。
and then restore the DB with the following command: 然后使用以下命令还原DB:
#mysql -u <username> -p <password> DB_name < <filename>.sql
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.