Home  >  Article  >  Database  >  Connect to and disconnect from MySQL server

Connect to and disconnect from MySQL server

WBOY
WBOYforward
2023-08-31 20:13:071418browse

连接到 MySQL 服务器和断开连接

You need to provide a MySQL username when calling 'mysql'. A password must be entered next. If the server is running on a different system than the one the user is logged into, you will also need to provide the hostname when trying to log in.

It is recommended to contact the administrator to find out the parameters required to connect to the server.

After determining the parameters, you need to use the following lines to connect to the server -

shell> mysql −h host −u user −p
Enter the password: ***

Here, ‘host’ represents the host name running the MySQL server. 'user' represents the username of the MySQL account. Replace appropriate values ​​in these places. *** stands for password. This is entered when "mysql" prompts "enter password".

After success, some introduction information will be displayed, followed by the "mysql>" prompt.

shell> mysql −h host −u user −p
Enter password: ********
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 25338 to server version: 8.0.25-standard

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

mysql>

The "mysql" prompt tells "mysql" that it is ready for the user to enter a SQL command and execute it.

NOTE: If the user is trying to log in on the same computer that is running MySQL, the hostname can be omitted and the following line can be run:

shell> mysql −u user −p

When trying to connect, if If a message similar to ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) appears, it means that the MySQL server daemon has been shut down (Unix) or the service (Windows) is currently not available. run. When this happens, you must contact your administrator.

After successful connection, if you wish to disconnect, please run the following line of code -

mysql> QUIT
Bye

The above is the detailed content of Connect to and disconnect from MySQL server. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete