How can we establish MySQL database by using MySQL binary at commandnprompt?

You can establish the MySQL database using the mysql binary at the command prompt. It can be understood with the help of the following example −


We can use following statements to connect to the MySQL server from the command prompt −

[root@host]# mysql -u root -p
Enter password:******

This will give us the mysql> command prompt where we will be able to execute any SQL command. Following is the result of above command −

The following code block shows the result of above code −

Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.20 MySQL Community Server (GPL)

Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective

Type 'help;' or '\h' for help. Type '\c' to clear the current input

In the above example, we have used root as a user but you can use any other user as well. Any user will be able to perform all the SQL operations, which are allowed to that user.

We can disconnect from the MySQL database any time using the exit command at mysql> prompt. 

mysql> exit