Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to switch to new user from MySQL console

Tags:

mysql

Im having a little problem in using mysql on windows. I know how to create a new user and giving grants to the new user and all. But i don't know how to switch to new user from mysql console!

like image 961
Sunil Kumar Avatar asked Jun 29 '12 18:06

Sunil Kumar


People also ask

How do I switch users in MySQL workbench?

How do I switch users in MySQL workbench? Within the connection tab, do one of the following: Click Users and Privileges from the Management list within the Navigator area. Click Server and then Users and Privileges from the menu.

How do I change to root user in MySQL?

For a server that is running as a Windows service, go to the Services manager: From the Start menu, select Control Panel, then Administrative Tools, then Services. Find the MySQL service in the list and stop it. ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass'; Save the file to disk.

How do I switch to MySQL in CMD?

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 have to exit and log in again using the new username.

From shell:

mysql --user=user_name --password=your_password db_name

Reference:

  • http://forums.mysql.com/read.php?10,247384,247391#msg-247391
  • http://dev.mysql.com/doc/refman//5.5/en/mysql.html
like image 50
Dil Avatar answered Oct 08 '22 18:10

Dil


Once you have your new user created, try changing your default shortcut to log in as that user directly instead.

Go to Start Menu > MySql x.x Command Line Client > right-clicked > Properties > Target and changed the user (from -uroot) to -uyournewuser:

"C:\Program Files\MySQL\MySQL Server 5.7\bin\mysql.exe" "--defaults-file=C:\ProgramData\MySQL\MySQL Server 5.7\my.ini" "-uroot" "-p"
like image 23
gtinker Avatar answered Oct 08 '22 16:10

gtinker