How to change the password of mysql

Source: Internet
Author: User
Tags mysql command line
There are many ways to change the root password. below I will summarize some common methods for changing the root password for MySQL data. if you need to know or forget the root password, you can refer to it. Method 1, Using mysqladmin


The following two commands are used: mysqladmin.exeand mysql.exe. the command format for changing the password of mysqladmin is as follows:

mysqladmin -u root -p[oldpass] password newpass

Note that oldpass (old password) is optional. if the default root password is blank, you do not need to enter it. if you need to change the old password, note that there is no space between the old password and-p, otherwise, an error is reported. In addition, the password and newpass are separated by spaces.

mysql -u rootmysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('newpass');

Method 2: In the DOS mode (the serial mode is positioned to the mysqlinstallation directory and in the sub-directory, and mysql.exe is used to enter, that is

C:Program FilesMySQLMySQL Server 5.1bin>mysql -u root -pEnter password: ******

Use the mysqladmin.exe command to modify the Mysql root password

Generally, the default Mysql root password is blank. if you have not set the root password before, use the mysqladmin command. you can use the following mysqladmin command to change the root password:

C:Program FilesMySQLMySQL Server 5.1bin>mysqladmin -u root -p password 123456Enter password:C:Program FilesMySQLMySQL Server 5.1bin>mysql -u root -p123456

As mentioned above, when mysqladmin is used to change the default password of root for the first time, Enter passwordto Enter the Mysql command line. Then, use the mysql.exe command to Enter the root and password.

If the root user has set a password, use the following method:

mysqladmin -u root password oldpass "newpass"

Method 3:Use UPDATE to directly edit the user table

mysql -u rootmysql> use mysql;mysql> UPDATE user SET Password = PASSWORD('newpass') WHERE user = 'root';mysql> FLUSH PRIVILEGES;

When the root password is lost

mysqld_safe --skip-grant-tables&mysql -u root mysqlmysql> UPDATE user SET password=PASSWORD("new password") WHERE user='root';mysql> FLUSH PRIVILEGES;

It is very convenient to use phpmyadmin to change the Mysql root password. after installing and configuring phpmyadmin, first log on to the management interface, click the Change Password link on the right, and enter the new Mysql root password you want to modify, click execute.

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.