Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mysql: whoami?

Tags:

mysql

Is there a whoami-like function in mysql?

I'm connecting to the mysql command line from a remote host. I'm not sure if my ip address is resolving to a domain name or not. I would like to see something like

mysql> whoami; +----------------------------------+ | User     | Host                  | +----------------------------------+ | username | resolved.hostname.com | +----------------------------------+ 1 row in set (0.00 sec) 

or

mysql> whoami; +------------------------+ | User     | Host        | +------------------------+ | username | 22.66.88.44 | +------------------------+ 1 row in set (0.00 sec) 
like image 253
user151841 Avatar asked May 04 '10 14:05

user151841


People also ask

How do I find my MySQL Whoami?

There is no whoami function in MySQL. The whoami can be used to know the current user in UNIX. Use user() or current_user() function from MySQL for the same purpose.

How do I switch from one user to another in MySQL?

If you want to login as a different user on MySQL, you need to use “mysql -u -p command”. The syntax is as follows to login as a different user.

How do I find MySQL username and password?

So for example, to show MySQL users' username, password and host, we'll modify the sql query to accordingly as such: mysql> select user, password, host from mysql. user; The above sql query will present you with a list of users and their respective user name, password and database host.

How do I connect to a MySQL user?

Enter mysql.exe -uroot -p , and MySQL will launch using the root user. MySQL will prompt you for your password. Enter the password from the user account you specified with the –u tag, and you'll connect to the MySQL server.


2 Answers

You can use the CURRENT_USER and USER functions as follows:

SELECT CURRENT_USER();  SELECT USER(); 

CURRENT_USER shows who you are authenticated as, while USER shows who you tried to authenticate as.

See the MySQL manual for more information.

like image 50
Håvard S Avatar answered Oct 21 '22 16:10

Håvard S


If you are using mysql command line utility then try \s command:

mysql> \s -------------- mysql  Ver 14.12 Distrib 5.0.67, for suse-linux-gnu (i686) using readline 5.2  Connection id:          519 Current database: Current user:           admin@localhost ......... Server version:         5.0.67 SUSE MySQL RPM ......... 
like image 40
Ivan Nevostruev Avatar answered Oct 21 '22 16:10

Ivan Nevostruev