简体   繁体   中英

How to set root user password for MySQL

I downloaded MySQL no install package from official site and installed it on windows 7.

It works great but when I run mysql.exe I can use the tools as root without any password.

I am using windows 7 32 bit and I am using mysql-noinstall-5.0.96 .

I want the root user to have a secure password. I want to create a root user or update the existing root user.

I have not used the install package you have used. However you can try the following. First check if the root user exists.

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. You SHOULD have at least one root user listed there. If I am correct you will see root listed but the password column would be NULL or BLANK.

You would now need to set the password for the root users. There are a couple of ways you can do this the first way is to use the SET_PASSWORD method.

Example of SET_PASSWORD method:

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

The other way that is commonly used is the UPDATE Method.

Example of the UPDATE method:

 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.

If you dont have a root user you will need to create it.

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.

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 .

How to set the root user password for MySQL:

  1. Go to phpmyadmin you should be presented with a username/password login.

  2. Login as root. If you never set a root password during mysql installation then the password is blank. 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.

  3. Now you are logged in as root in 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".

  6. The root password is now changed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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