Showing posts with label mysql command line. Show all posts
Showing posts with label mysql command line. Show all posts

Friday, June 28, 2013

Connect XAMPP's mysql on Linux terminal

Access XAMPP's mysql on Linux command line :

If you want to operate xampp's mysql on Linux terminal, follow the procedure.

By default, if you run
# mysql
It tries to connect to default mysql of the system and unfortunately default mysql is not XAMPP's mysql.

To open the xampp's mysql prompt on terminal, Run following command.
# /opt/lampp/bin/mysql or # /opt/lampp/bin/mysql -u root or # /opt/lampp/bin/mysql -h localhost -u root -p Default Password is blank, just press enter key.
/opt/lampp/bin/mysql is the path of the mysql binary file of xampp.

If you want to run XAMPP's mysql using 
# mysql
You should follow these steps.

1) Stop xampp & copy file /opt/lampp/bin/mysql
2) Rename the file /usr/bin/mysql to /usr/bin/mysql_default
    If you haven't installed mysql on your system, you will not get the file.
3) Paste file  /opt/lampp/bin/mysql into /usr/bin
4) Now whenever you will run mysql on terminal, it will open XAMPP"s mysql prompt.

Saturday, May 11, 2013

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"

where 
hostname is name of your host. If you upload on your system it can be localhost or 127.0.0.1. 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

Examples:

a) If you want to upload file on your localhost, the command would be (if root has no password)
$ mysql -h 127.0.0.1 -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 192.168.1.7 -u john -p'johnathan' "webpro" < /home/user/documents/webpro.sql

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

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