MySQL 显示当前连接信息
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3613704/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
MySQL show current connection info
提问by brutustea
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.
我在 MySQL 终端会话中,但我不知道我连接到哪个服务器,或者我连接到哪个数据库。
Is there a MySQL command that will tell me the host, port, and username and database I am using now?
是否有一个 MySQL 命令会告诉我我现在使用的主机、端口、用户名和数据库?
回答by 2ndkauboy
There are MYSQL functions you can use. Like this one that resolves the user:
您可以使用 MYSQL 函数。像这样解决用户的问题:
SELECT USER();
This will return something like root@localhost
so you get the host and the user.
这将返回类似这样的内容,root@localhost
以便您获得主机和用户。
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
其他有用的功能可以在这里找到:http: //dev.mysql.com/doc/refman/5.0/en/information-functions.html
回答by Just a learner
You can use the statuscommand in MySQL client.
您可以在 MySQL 客户端中使用status命令。
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>
回答by Nikhil Agrawal
If you want to know the port number of your local host on which Mysqlis running you can use this query on MySQL Command line client --
如果您想知道运行Mysql 的本地主机的端口号,您可以在 MySQL 命令行客户端上使用此查询——
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.
它将为您提供运行 MySQL 的端口号。
If you want to know the hostname of your Mysqlyou can use this query on MySQL Command line client --
如果你想知道你的 Mysql的主机名,你可以在 MySQL 命令行客户端上使用这个查询——
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.
它将为您提供 mysql 的主机名。
If you want to know the username of your Mysqlyou can use this query on MySQL Command line client --
如果你想知道你的 Mysql的用户名,你可以在 MySQL 命令行客户端上使用这个查询——
select user();
mysql> select user();
+----------------+
| user() |
+----------------+
| root@localhost |
+----------------+
1 row in set (0.00 sec)
It will give you the username for mysql.
它将为您提供 mysql 的用户名。