Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I'm somehow in a MySQL session but I don't know what server I am connected to, etc. Is there a MySQL command that will tell me the host, port, and username I am using now?

Thanks!

share|improve this question
2  
Port can be picked up using "show variables like 'port'" –  martin clayton Aug 31 '10 at 23:55
    
Thanks "martin clayton" –  brutustea Sep 1 '10 at 19:29
    
"I'm somehow in a MySQL session..." <- can't help loving this, thanks! :)) –  Sz. Apr 3 at 17:43
add comment

3 Answers

up vote 38 down vote accepted

There are MYSQL function you can use for that like this one that resolves the user:

SELECT USER();

This will return somethin like 'root@localhost' so you get the host and the user.

To get the current database run this statement:

SELECT DATABASE();

These and also some other useful functions can be found here: http://dev.mysql.com/doc/refman/5.0/en/information-functions.html

share|improve this answer
    
Thanks homeslice. –  brutustea Aug 31 '10 at 22:59
add comment

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>
share|improve this answer
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.