Home > Database > Mysql Tutorial > body text

Connect to and disconnect from MySQL server

WBOY
Release: 2023-08-31 20:13:07
forward
1382 people have browsed it

连接到 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: ***
Copy after login

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>
Copy after login

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
Copy after login

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
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!