开发者

mysql restore database script with create clause?

mysql> -u username -p [database] < file.sql

restores database. I do not have a create clause in my dumped file, hence I need to create a database and t开发者_StackOverflowhen restore. I can do this to create.

mysql> create database [database];

Fair enough. Now how can I achieve the above restoration in one line? Is there anyway to restore a database by creating the database before that with a single line of code?

I can certainly live without it, but would be nice to know.. Thanks..


(echo "create database XYZ; use XYZ;"; cat file.sql) | mysql -u username -p

could do the trick.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜