MySQL是一种关系型数据库,在使用中经常需要检测数据库是否已经连接上主机了,接下来我们就来介绍一下如何检测MySQL连接上主机了。
步骤:
1. 打开MySQL命令行客户端:
mysql -u用户名 -p密码
2. 输入以下命令,查看是否连接成功:
status
如果连接成功,会显示以下信息:
--------------
mysql Ver 14.14 Distrib 5.7.32, for Linux (x86_64) using EditLine wrapper
Connection id: 2590
Current database:
Current user: root@localhost
SSL: Not in use
Current pager: stdout
Using outfile: ''
Using delimiter: ;
Server version: 5.7.32-0ubuntu0.18.04.1 (Ubuntu)
Protocol version: 10
Connection: Localhost via UNIX socket
Server characterset: utf8mb4
Db characterset: utf8mb4
Client characterset: utf8mb4
Conn. characterset: utf8mb4
UNIX socket: /var/run/mysqld/mysqld.sock
Uptime: 15 min 22 sec
Threads: 1 Questions: 11 Slow queries: 0 Opens: 106 Flush tables: 1 Open tables: 100 Queries per second avg: 0.011
--------------
3. 如果连接失败,会显示以下信息:
ERROR 1045 (28000): Access denied for user 'username'@'localhost' (using password: YES)
经过以上步骤,我们就可以很方便地检测MySQL是否连接上主机了。