MySQL show current connection info
I am in a MySQL terminal session but I don't know what server I am connected to, or what database I am connected to.
Is there a MySQL command that will开发者_如何转开发 tell me the host, port, and username and database I am using now?
There are MYSQL functions you can use. Like this one that resolves the user:
SELECT USER();
This will return something like root@localhost
so you get the host and the user.
To get the current database run this statement:
SELECT DATABASE();
Other useful functions can be found here: http://dev.mysql.com/doc/refman/5.0/en/information-functions.html
You can use the status command in MySQL client.
mysql> status;
--------------
mysql Ver 14.14 Distrib 5.5.8, for Win32 (x86)
Connection id: 1
Current database: test
Current user: ODBC@localhost
SSL: Not in use
Using delimiter: ;
Server version: 5.5.8 MySQL Community Server (GPL)
Protocol version: 10
Connection: localhost via TCP/IP
Server characterset: latin1
Db characterset: latin1
Client characterset: gbk
Conn. characterset: gbk
TCP port: 3306
Uptime: 7 min 16 sec
Threads: 1 Questions: 21 Slow queries: 0 Opens: 33 Flush tables: 1 Open tables: 26 Queries per second avg: 0.48
--------------
mysql>
If you want to know the port number of your local host on which Mysql is running you can use this query on MySQL Command line client --
SHOW VARIABLES WHERE Variable_name = 'port';
mysql> SHOW VARIABLES WHERE Variable_name = 'port';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| port | 3306 |
+---------------+-------+
1 row in set (0.00 sec)
It will give you the port number on which MySQL is running.
If you want to know the hostname of your Mysql you can use this query on MySQL Command line client --
SHOW VARIABLES WHERE Variable_name = 'hostname';
mysql> SHOW VARIABLES WHERE Variable_name = 'hostname';
+-------------------+-------+
| Variable_name | Value |
+-------------------+-------+
| hostname | Dell |
+-------------------+-------+
1 row in set (0.00 sec)
It will give you the hostname for mysql.
If you want to know the username of your Mysql you can use this query on MySQL Command line client --
select user();
mysql> select user();
+----------------+
| user() |
+----------------+
| root@localhost |
+----------------+
1 row in set (0.00 sec)
It will give you the username for mysql.
精彩评论