通过命令行将大型SQL文件导入MySql [英] Importing large sql file to MySql via command line

查看:126
本文介绍了通过命令行将大型SQL文件导入MySql的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过Ubuntu中的命令行将大约300MB的sql文件导入MySql.我用

I'm trying to import an sql file of around 300MB to MySql via command line in Ubuntu. I used

source /var/www/myfile.sql;

现在它正在显示看似无限的行:

Right now it's displaying a seemingly infinite rows of:

Query OK, 1 row affected (0.03 sec)

但是它已经运行了一段时间.我之前没有导入过这么大的文件,所以我只想知道这是否正常,如果进程停止运行或出现一些错误,它将显示在命令行中还是无限期进行?

However it's been running a little while now. I've not imported a file this large before so I just want to know whether this is normal, if the process stalls or has some errors, will this show up in command line or will this process go on indefinitely?

谢谢

推荐答案

您可以使用如下所示的标准输入来导入.sql文件:

You can import .sql file using the standard input like this:

mysql -u <user> -p<password> <dbname> < file.sql

注意: <-p><password>

参考: http://dev.mysql. com/doc/refman/5.0/en/mysql-batch-commands.html

建议的编辑注意事项:通过建议的编辑使用内嵌密码参数,此答案略有更改.我可以将其推荐给脚本,但是您应该意识到,当直接在参数(-p<password>)中写入密码时,shell历史记录可能会缓存它,从而向任何可以读取历史记录文件的人透露您的密码.而-p要求您通过标准输入来输入密码.

Note for suggested edits: This answer was slightly changed by suggested edits to use inline password parameter. I can recommend it for scripts but you should be aware that when you write password directly in the parameter (-p<password>) it may be cached by a shell history revealing your password to anyone who can read the history file. Whereas -p asks you to input password by standard input.

这篇关于通过命令行将大型SQL文件导入MySql的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆