- Trending Categories
- Data Structure
- Operating System
- C Programming
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Connecting to and Disconnecting from the MySQL Server
A MySQL user name needs to be provided when ‘mysql’ is invoked. Next a password has to be entered. If the server runs on a system which is not the same as that on which the user logs in, the host name also needs to be provided while trying to log in.
It is suggested to contact the administrator to find out the parameters that are required to connect to the server.
Once the parameters are determined, the below lines need to be sued to connect to the server −
shell> mysql −h host −u user −p Enter the password: ***
Here, ‘host’ represents the name of the host where the MySQL server is running. The ‘user’ represents the user name of the MySQL account. The appropriate values are substituted in these places. The *** represents the password. This is entered when ‘mysql’ prompts ‘Enter the password’.
Once this is successful, some introductory information is displayed, and this is followed by ‘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 that ‘mysql’ is ready for the user to enter their SQL commands and execute it.
Note: If the user is trying to log in from the same machine where MySQL is running, the host name can be omitted, and the below line can be run instead:
shell> mysql −u user −p
When trying to connect, if a message like ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2), shows up, it indicates that the MySQL server daemon (Unix) or service (Windows) is not running currently. When this happens, the administrator has to be contacted.
Once the connection is successful, and you wish to disconnect, run the below lines of code −
mysql> QUIT Bye
- Command Options for Connecting to the MySQL Server
- Connecting to the MySQL Server Using Command Options
- After connecting to MySQL server how can we select a database from\ncommand prompt?
- Connecting to MySQL database from the command line?
- Error while connecting to SAP server from Java application: java.lang.UnsatisfiedLinkError: no sapjco3 in java.library.path
- Connecting to SAP HANA server on Cloud using PHP
- Connecting to SAP R/3 system via JCo client and JCo Server
- How to copy tables or databases from one MySQL server to another MySQL server?
- MySQL Server and Server-Startup Programs
- How to upgrade MySQL server from command line?
- Disconnecting Database in Python
- Connecting to a MySQL database with Java
- Starting and Stopping MySQL Server
- mysqld - The MySQL Server
- How to disable “Establishing SSL connection without server's identity verification is not recommended” warning when connecting to MySQL database in Java?