Database Design & Management Project using MySQL

profiledhriase
ConnecttoMySQLServer.docx

Connect to MySQL Server

If this site saves you hours of work, please whitelist it in your ad blocker or

donate now

to support us creating more free content in the future.

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 the interactive and non-interactive mode.

The mysql command-line client is typically located in the bin directory of the 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:

1

mysql

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

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

1

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:

1

Enter password: ********

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

1

mysql>

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

1

mysql> show databases;

Here is the output:

1

2

3

4

5

6

7

8

9

+--------------------+

| 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.

connect to mysql - mysql workbench step 1

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

Just click the + button in 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.

connect to mysql - mysql workbench step 2

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.

connect to mysql - mysql workbench step 4

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

connect to mysql - mysql workbench step 5

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

connect to mysql - mysql workbench step 6

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

connect to mysql - mysql workbench step 7

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