Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Putty to import a sql file into the database

I want to import an .sql file into a database on the server through command line.

I understand that I should use the follow line:

mysql -u username -p database_name < textfilewithsqlstatments.sql

the sql file is currently in my local folder, shall I upload it to the server first? how should I specify the directory for this file?

Thanks

like image 819
the_summer_bee Avatar asked Sep 27 '13 12:09

the_summer_bee


2 Answers

The line

mysql -u username -p database_name < textfilewithsqlstatments.sql

Assumes that the file is in the same directory that you are running the command from.

You should upload the file to the server and specify the path as

mysql -u username -p database_name < /path/to/file/on/server/textfilewithsqlstatments.sql
like image 184
Othrayte Avatar answered Sep 28 '22 05:09

Othrayte


U can use the putty utility PLINK.EXE

Preferred configure the session with a key, to not need to put the password in all the connections, so simple use:

plink mysql -u username -p database_name < textfilewithsqlstatments.sql

Considering that the file

textfilewithsqlstatments.sql

is in your /home/user.

More information about PLINK: http://the.earth.li/~sgtatham/putty/0.58/htmldoc/Chapter7.html

It works fine!

like image 30
Celso Marigo Jr Avatar answered Sep 28 '22 06:09

Celso Marigo Jr