Connect to MySQL from the command line

2024-04-25 13:09:42 Raju Mysql

How to connect to MySQL from the command line?

To operate MySQL from the command line, you must first connect to MySQL.

Use the following mysql command to connect to MySQL Server.

mysql -u user name -D database name -p

The -u option specifies the username to connect to MySQL.

-D option specifies the name of the database to connect to.

Specify the -p option to send a password.

For example, to connect to the test database as the root user, execute the command as follows.

Since the root user has a password, the -p option is also added.

E: \ MySQL \ bin> mysql -u root -D test -p
Enter password: ***********
Welcome to the MySQL monitor.Commands end with; or \ g.
Your MySQL connection id is 1 to server version: 4.1.19-community-nt
Type 'help;' or '\ h' for help.Type '\ c' to clear the buffer.
mysql>


If the connection is successful, the mysql prompt is displayed.

If you want to connect, run \ q to exit the prompt.


mysql> \ q
Bye

This post is submitted by one of our members. You may submit a new post here.

Related Tricks