How to connect to the MySQL database?

MySQL allows us to connect with the database server in mainly two ways:

Using Command-line Tool

We can find the command-line client tool in the bin directory of the MySQL’s installation folder. To invoke this program, we need to navigate the installation folder’s bin directory and type the below command:

  1. mysql  

Next, we need to run the below command to connect to the MySQL Server:

  1. shell>mysql -u root -p  

Finally, type the password for the selected user account root and press Enter:

  1. Enter password: ********  

After successful connection, we can use the below command to use the:

  1. USE database_name;  

Using MySQL Workbench

We can make a connection with database using MySQL Workbench, simply clicking the plus (+) icon or navigating to the menu bar -> Database -> Connect to Database, the following screen appears. Now, you need to fill all the details to make a connection:

MySQL Interview Questions

Once we finished this setup, it will open the MySQL Workbench screen. Now, we can double click on the newly created connection to connect with the database server.