MySQL Set Password method summary (linux/windows)

Source: Internet
Author: User
Tags flush mysql in

MySQL under Windows

(for administrators or users with global permissions to reset another user's password)

Enter command line mode

The code is as follows Copy Code
Mysql-u Root MySQL
mysql> UPDATE user SET Password=password ("New password") WHERE user= ' name ';
mysql> FLUSH privileges;
Mysql> QUIT


Method Two:
(Apply ditto, just different method)

The code is as follows Copy Code
Mysql-u Root MySQL
Mysql> SET PASSWORD for Name=password (' New PASSWORD ');
Mysql> QUIT


(These two methods I am not commonly used, if the administrator, I will use other tools such as phpMyAdmin or mysql-front to manage user rights, more intuitive and convenient)

Quick Summary

The code is as follows Copy Code

A../mysqladmin-u root-p OldPassword newpasswd (remember this command is in the/usr/local/mysql/bin in the external command)

B. SET PASSWORD for Root=password (' New PASSWORD ') (in this way after logging in to the database)

C. UPDATE user SET Password=password ("New password") WHERE user= ' root '; (This way after logging in to the database)


MySQL in Linux

MySQL how to set the root password method one:

The simplest way is to install MySQL after the system prompts the method. Use Mysqladmin to complete.

The code is as follows Copy Code

shell> mysqladmin-u root password "newpwd"

shell> mysqladmin-u root-h host_name password "newpwd" password

The following double quotes are not required, but quotation marks are required if the password contains spaces or some special symbols. Method MySQL How to set the root password two: Use the MySQL inside the Set password command to complete, note must use the password () function to encrypt the set of this newpwd, otherwise directly = ' newpwd ' will not take effect. However, if you use the method to set the password with mysqladmin password or grant, you do not need to use the password () function, because they have automatically called the function.

The code is as follows Copy Code

shell> Mysql-u Root


mysql> SET PASSWORD for ' root ' @ ' localhost ' = PASSWORD (' newpwd ');

mysql> SET PASSWORD for ' root ' @ ' host_name ' = PASSWORD (' newpwd ');


MySQL how to set the root password method three:


Set the password directly through the Update user table

The code is as follows Copy Code

shell> Mysql-u Root

mysql> UPDATE mysql.user SET Password = Password (' newpwd ')

-> WHERE User = ' root ';

mysql> FLUSH privileges;

If you forget the MySQL root password you can take the following steps to reset

1. Kill all MySQL Processes

2. Use--skip-grant-tables parameters to start MySQL

The code is as follows Copy Code

Shell> Mysqld_safe--skip-grant-tables &

The last must kill skill:

The code is as follows Copy Code

mysqladmin-u root "Old password" "New password"

Solution: The above has name, please use your username to replace. There is a new password please enter the password you want to set.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.