NSC
NSC

Reputation: 11

Switch user from root to another user in MySQL through command line

I installed MySQL database in my machine. I was new to MySQL, can anyone help me with query used to switch to another user in MySQL through command line. Thanks in advance.

Upvotes: 1

Views: 8042

Answers (2)

user8406805
user8406805

Reputation:

It's an easy step, you can simply use the "system mysql -uvivek -p" from "mysql" CLI.

Logging into first your:

[vivek@centosnode1 ~]$ mysql -uroot -p
Enter password: 

mysql> select user();
+----------------+
| user()         |
+----------------+
| root@localhost |
+----------------+
1 row in set (0.06 sec)

Logging into different user within mysql CLI

mysql> system mysql -uvivek -p
Enter password: 

mysql> select user();
+-----------------+
| user()          |
+-----------------+
| vivek@localhost |
+-----------------+
1 row in set (0.00 sec)

mysql> 

Upvotes: 4

Maaz Ali
Maaz Ali

Reputation: 83

You can try executing this command on mysql directory.

mysql -u yourusername -p

After pressing enter it'll ask for the password and you're in.

Happy Coding.

Upvotes: 0

Related Questions