The MySQL database is one of the well know database engine, which uses a client-server architecture. The server, mysqld is the program that actually manipulate the database. In order to talk to server, we use a client program called structured query language (SQL).
In this post I would like to show, issuing SQL queries from the command-line using MySQL client, in order to issue SQL queries first we should establish a connection to the MySQL server from the command-line.
Invoking the MySQL Client
let’s run $: mysql
in your terminal, if your command interpreter can not find it. Add the directory where MySQL is installed to your PATH stetting. Then you can run MySQL from any directory easily. or you can type full path-name each time you run it. the command look like this under Unix and windows as follows $ /usr/local/mysql/bin/mysql
,C:\MYSQL\Bin>
To log into the MySQL issue following command
mysql -h localhost -u root -p; Enter Password: your_password
Here each option is single-dash “shot” form. -h and -u is to specify the hostname, user and -p to be promoted for the password.
We can also connect to the MySQL server using double-dash long forms, –host, –user and –password, use them as shown below.
mysql --host=localhost --user=root --password; Enter Password: your_password
After entering the correct password you will be met with the following greeting and MySQL prompt:
That’s it!. After establishing connection you can execute all SQL statements from terminal. For example let’s create a database
mysql> CREATE DATABASE arjunphp; Query OK, 1 row affected (0.00 sec)