在 MySQL 中以特定用户身份进行身份验证
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11394940/
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
Authenticate as a specific user in MySQL
提问by Jones
I'm a Brand new User to MySQL DB, have installed the WAMPSERVER and I'm using MySQL through the MySQL console.
我是 MySQL 数据库的全新用户,已经安装了 WAMPSERVER 并且我正在通过 MySQL 控制台使用 MySQL。
Query_1: Every time that I log in, it directly asks me for the password of root. However, i want to log in as a different user.
Query_1:每次登录时直接问我root密码。但是,我想以其他用户身份登录。
Query_2: If at all i do login as root, i want to switch user without closing the console.
Query_2:如果我确实以 root 身份登录,我想在不关闭控制台的情况下切换用户。
How can I do this?
我怎样才能做到这一点?
Thank you.
谢谢你。
采纳答案by feeela
If you attempt to login without specifying a user-name, MySQL will assume "root". In most cases you don't switch the user, but give a single user all the required rights;, for example to access multiple databases. If that is not possible for you, you can use two MySQL connections with two different users simultaneously.
如果您尝试在未指定用户名的情况下登录,MySQL 将假定为“root”。在大多数情况下,您不会切换用户,而是授予单个用户所有必需的权限;例如访问多个数据库。如果这对您来说是不可能的,您可以同时使用两个不同用户的两个 MySQL 连接。
回答by Tamás Szincsák
You can specify your username and password like this:
您可以像这样指定您的用户名和密码:
shell> mysql --user=user_name --password=your_password db_name
As far as I know, there is no way to change user after login without restarting the client.
据我所知,登录后没有办法在不重启客户端的情况下更改用户。
回答by Jon Taylor
I don't think its possible to switch users while in the console itself. You have to login with the different user instead.
我认为在控制台中切换用户是不可能的。您必须改为使用其他用户登录。
Logging in use this command
使用此命令登录
mysql -u username -p
Then it will prompt for the password.
然后它会提示输入密码。
回答by William
It is not possible to switch users in the MySQL console using WAMP. You must use SQL through the windows command line to switch users.
无法使用 WAMP 在 MySQL 控制台中切换用户。您必须通过 windows 命令行使用 SQL 来切换用户。
Steps (win 8):
步骤(赢8):
1) Start
1) 开始
2) Type: 'command prompt'
2)输入:'命令提示符'
3) Type: 'cd /'
3) 输入:'cd /'
4) Navigate to where WAMP bin is located, my location is: C:\wamp\bin\mysql\mysql5.6.17\bin by typing: 'CD wamp\bin\mysql\mysql5.6.17\bin'
4)导航到WAMP bin所在的位置,我的位置是:C:\wamp\bin\mysql\mysql5.6.17\bin,输入:'CD wamp\bin\mysql\mysql5.6.17\bin'
5) run SQL under new user by typing 'mysql -u (username you want to use) -p (database you want to connect to)'
5)通过键入'mysql -u(您要使用的用户名)-p(您要连接的数据库)'在新用户下运行SQL
You will now be logged in as a new user.
您现在将作为新用户登录。
回答by user3778731
The MySQL console provided in the wampserver admin panel, once a password is set, will prompt you for the root user's password before you can do anything. In order to log-in as a different user you need to log-in from the command-line. In order to this however, you'll need to add the file pathway to your installation of MySQL's bin folder to your user environment pathway so that your system will be able to access MySQL from the command line. To do this on windows open up file explorer, click on your C drive, open the wamp folder, open bin folder, open MySQL folder, open the MySQL folder with your installation version, open the bin folder you find there. In the file pathway bar of file explorer click on the folder icon to the left to generate the pathway to this bin folder, copy the pathway. Next open up control panel, in the search bar type the string environment variables, select edit user environment... you don't want to mess with the system environment, on the screen that appears choose the PATH variable- if it's not there then add it. Finally paste in the file pathway to MySQL's bin folder. Open up a command prompt and type mysql -u uswername -p hit return and then you'll be prompted for that user's password. Assuming of course you've made another user already.
wampserver 管理面板中提供的 MySQL 控制台,一旦设置了密码,将在您执行任何操作之前提示您输入 root 用户的密码。为了以不同的用户身份登录,您需要从命令行登录。但是,为此,您需要将安装 MySQL 的 bin 文件夹的文件路径添加到您的用户环境路径,以便您的系统能够从命令行访问 MySQL。要在 Windows 上执行此操作,请打开文件资源管理器,单击您的 C 驱动器,打开 wamp 文件夹,打开 bin 文件夹,打开 MySQL 文件夹,打开安装版本的 MySQL 文件夹,打开您在那里找到的 bin 文件夹。在文件资源管理器的文件路径栏中,点击左侧的文件夹图标,生成到这个bin文件夹的路径,复制路径。接下来打开控制面板,在搜索栏中输入字符串环境变量,选择编辑用户环境...您不想弄乱系统环境,在出现的屏幕上选择 PATH 变量 - 如果它不存在,则添加它。最后将文件路径粘贴到 MySQL 的 bin 文件夹中。打开命令提示符并键入 mysql -u uswername -p 回车,然后系统会提示您输入该用户的密码。当然,假设您已经创建了另一个用户。将提示输入该用户的密码。当然,假设您已经创建了另一个用户。将提示输入该用户的密码。当然,假设您已经创建了另一个用户。
As far as I know, once logged in as the root or any other user, the only way to switch is to exit mysql and then enter again as a different user.
据我所知,一旦以 root 或任何其他用户身份登录,切换的唯一方法是退出 mysql,然后以不同的用户身份再次进入。