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
1 2 |
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.
1 2 |
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
1 2 |
mysql> CREATE DATABASE arjunphp; Query OK, 1 row affected (0.00 sec) |
I hope you like this Post, Please feel free to comment below, your suggestion and problems if you face - we are here to solve your problems.
I am Arjun from Hyderabad (India). I have been working as a software engineer from the last 7+ years, and it is my passion to learn new things and implement them as a practice. Aside from work, I like gardening and spending time with pets.