开发者

mysql restore database script with create clause?

开发者 https://www.devze.com 2023-03-27 09:24 出处:网络
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
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

精彩评论

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