如何从 MySQL 控制台切换到新用户
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11266957/
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
How to switch to new user from MySQL console
提问by Sunil Kumar
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!
我在 Windows 上使用 mysql 时遇到了一个小问题。我知道如何创建一个新用户并授予新用户和所有用户。但我不知道如何从 mysql 控制台切换到新用户!
回答by Dil
You have to exit and log in again using the new username.
您必须退出并使用新用户名再次登录。
From shell:
从外壳:
mysql --user=user_name --password=your_password db_name
Reference:
参考:
回答by gtinker
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
:
转到开始菜单 > MySql xx 命令行客户端 > 右键单击 > 属性 > 目标并将用户(从-uroot
)更改为-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"
回答by khalid sadig
When we open MySQL through MySQL console of WampServer it directly logs in as root. So what I did was I logged in through command prompt and it worked. E:\InstalledFiles\MySql\bin\mysql\mysql5.5.24\bin
This is where my mysql.exe
file is. So I went till bin and gave this command in the command prompt mysql -u root -p
. So I could login as root from command prompt.
当我们通过 WampServer 的 MySQL 控制台打开 MySQL 时,它直接以 root 身份登录。所以我所做的是通过命令提示符登录并且它起作用了。 E:\InstalledFiles\MySql\bin\mysql\mysql5.5.24\bin
这是我的mysql.exe
文件所在的位置。所以我一直到 bin 并在命令提示符下给出了这个命令mysql -u root -p
。所以我可以从命令提示符以 root 身份登录。