Import mysql database using command line in Linux

Upload mysql database command :

If you want to import a mysql database using command line, here is the command.
$ mysql -h host-name -u username -p'password' "database_name" < "path/of/the/sql/file"

hostname is name of your host. If you upload on your system it can be localhost or If you would upload on server it would be IP of the server.
username is username of mysql user
password is password of mysql user, Remember there is no space between -p & single quote (')
database_name is name of your database in which you want to upload the sql file


a) If you want to upload file on your localhost, the command would be (if root has no password)
$ mysql -h -u root "database_name" < /path/of/the/sql/file

b) If you want to upload file on other system of same LAN, the command would be
$ mysql -h -u john -p'johnathan' "webpro" < /home/user/documents/webpro.sql

where - IP of other system of same LAN
john is username of mysql user
johnathan is his password
webpro is database name

Please create database first before running above command otherwise it would give error "ERROR 1049 (42000): Unknown database 'webpro'"

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...