How to connect to MySQL from the command line

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

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.

After entering the correct password you will be met with the following greeting and MySQL prompt:
mysql connect

That’s it!. After establishing connection you can execute all SQL statements from terminal. For example let’s create a database

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.

0 0 vote
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
DMCA.com Protection Status
0
Would love your thoughts, please comment.x
()
x