Connect to MySQL Server

Connect to MySQL Server

 Connect to MySQL Server




Summary: in this tutorial, you will learn how to connect to MySQL Server using MySQL command-line client and MySQL Workbench.

Once you have the MySQL Server installed, you can connect to it using any client program such as MySQL command-line client and MySQL workbench.

Connect to MySQL Using MySQL command-line client

MySQL is a command-line client program that allows you to interact with MySQL in interactive and non-interactive modes.

The MySQL command-line client is typically located in the bin directory of MySQL’s installation folder.

To invoke the MySQL program, you just simply navigate to the bin directory of the MySQL’s installation folder and type:

mysql

If the MySQL program is already in the PATH, you can simply invoke it using the MySQL command.

To connect to the MySQL Server, you use this command:

shell>mysql -u root -p

-u root means that you connect to the MySQL Server using the user account root.

-p instructs MySQL to prompt for a password.

You type the password for the user account root and press Enter:

Enter password: ********

If everything is OK, you will connect to the MySQL Server with the following command:

mysql>

To display the databases in the current server, you use the SHOW DATABASES statement:

mysql> show databases;

Here is the output:

+--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | sys | +--------------------+ 4 rows in set (0.01 sec)

Connect to MySQL Using MySQL Workbench

Step 1. Launch the MySQL Workbench.

You can connect to a MySQL Server using the Database > Connect to Database… menu or click the + button that is located next to the MySQL Connections.

Just click the + button next to the MySQL Connections to continue.

Step 2. Enter the connection name e.g., Localhost. You can name it whatever makes sense to you. By default, the username is root. If you use a different user account, you can change it in the Username textbox.

Step 3. Click the Store in Vault ... button to enter the password for the provided user account. A window will display. You enter the password and click the OK button.

Step 4. Click the Test Connection button to test if the connection to the MySQL Server is successful or not. Then click the OK button if the connection is established successfully.

Step 5. Click the OK button to save the connection.

Step 6. Click the newly created connection under MySQL Connections to connect to the MySQL Server:

Step 7. MySQL Workbench display with the current schemas and a pane for entering queries:

In this tutorial, you have learned how to connect to the MySQL Server using MySQL command-line client and MySQL Workbench.

Reactions

Post a Comment

0 Comments

close