简体   繁体   English

如何为MySQL设置root用户密码

[英]How to set root user password for MySQL

I downloaded MySQL no install package from official site and installed it on windows 7. 我从官方网站下载了MySQL no install软件包并将其安装在Windows 7上。

It works great but when I run mysql.exe I can use the tools as root without any password. 它工作得很好,但是当我运行mysql.exe我可以以root用户身份使用这些工具而无需输入任何密码。

I am using windows 7 32 bit and I am using mysql-noinstall-5.0.96 . 我正在使用Windows 7 32位,并且正在使用mysql-noinstall-5.0.96

I want the root user to have a secure password. 我希望root用户具有安全的密码。 I want to create a root user or update the existing root user. 我想创建一个root用户或更新现有的root用户。

I have not used the install package you have used. 我没有使用过您使用过的安装包。 However you can try the following. 但是,您可以尝试以下方法。 First check if the root user exists. 首先检查root用户是否存在。

Execute the following code: 执行以下代码:

 SELECT User
        , Host
        , Password
 FROM mysql.user
 WHERE User='root'

This will return a list of the users with the root userid. 这将返回具有root用户ID的用户列表。 You SHOULD have at least one root user listed there. 您应该在那里至少列出了一个root用户。 If I am correct you will see root listed but the password column would be NULL or BLANK. 如果我是正确的,您会看到列出了root,但密码列将为NULL或BLANK。

You would now need to set the password for the root users. 现在,您需要为root用户设置密码。 There are a couple of ways you can do this the first way is to use the SET_PASSWORD method. 有两种方法可以执行此操作,第一种方法是使用SET_PASSWORD方法。

Example of SET_PASSWORD method: SET_PASSWORD方法的示例:

 SET PASSWORD FOR 'root'@'localhost' = PASSWORD('newpwd');

The other way that is commonly used is the UPDATE Method. 常用的另一种方法是UPDATE方法。

Example of the UPDATE method: UPDATE方法的示例:

 UPDATE mysql.user SET Password = PASSWORD('newpwd')
 WHERE User = 'root';
 FLUSH PRIVILEGES;

This method will update the mysql.user table directly and you would need to run the FLUSH PRIVILEGES to make sure the system security is reset. 该方法将直接更新mysql.user表,您将需要运行FLUSH PRIVILEGES以确保重置系统安全性。

If you dont have a root user you will need to create it. 如果您没有root用户,则需要创建它。

This link is worth reading https://dev.mysql.com/doc/refman/5.5/en/default-privileges.html as it shows you all about default settings etc. 该链接值得阅读https://dev.mysql.com/doc/refman/5.5/en/default-privileges.html,因为它向您展示了有关默认设置的所有信息。

If you need to create a new user please check the following link http://dev.mysql.com/doc/refman/5.1/en/create-user.html . 如果您需要创建新用户,请检查以下链接http://dev.mysql.com/doc/refman/5.1/en/create-user.html

How to set the root user password for MySQL: 如何为MySQL设置root用户密码:

  1. Go to phpmyadmin you should be presented with a username/password login. 转到phpmyadmin,您应该看到一个用户名/密码登录名。

  2. Login as root. 以root身份登录。 If you never set a root password during mysql installation then the password is blank. 如果您从未在mysql安装过程中设置root密码,则密码为空。 If you did set one, and you forgot what it is, then read: http://dev.mysql.com/doc/refman/5.0/en/resetting-permissions.html or blow away mysql and reinstall while paying attention to the set password dialog. 如果您确实设置了一个,而忘记了它,请阅读: http : //dev.mysql.com/doc/refman/5.0/en/resetting-permissions.html或删除mysql并重新安装,同时注意以下内容:设置密码对话框。

  3. Now you are logged in as root in phpmyadmin. 现在,您以root用户身份登录phpmyadmin。

  4. Under General settings click "Change password" link. 在常规设置下,单击“更改密码”链接。

  5. You are presented with a password reset popup box, type in your password twice to confirm and press "Go". 将显示一个密码重置弹出框,输入两次密码以确认并按“ Go”。

  6. The root password is now changed. 现在,root密码已更改。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM