Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Importing large sql file to MySql via command line

Tags:

mysql

ubuntu

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?

Thanks

like image 878
user2028856 Avatar asked Oct 20 '13 21:10

user2028856


People also ask

How do I run a big SQL script in MySQL?

To execute a large script, do the following: To open the Execute Script Wizard, go to the Database menu, and click Execute Large Script. Click the Connection field to select a connection to a required database server against which you want to execute your script.


1 Answers

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

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

Note: There shouldn't space between <-p> and <password>

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

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.

like image 123
Martin Nuc Avatar answered Oct 11 '22 01:10

Martin Nuc