Four ways to change the default password of MySQL _ MySQL

Source: Internet
Author: User
Tags password protection
After MySQL is installed on windows, the system has generated a license table and an account by default. next we will teach you how to change the default password of MySQ. After the MySQL database is installed on windows, the system has generated a license table and an account by default, you do not need to execute the mysql_install_db script on the Unix platform to generate an account and the corresponding permission table. However, if you do not use the MSI format to install MySQL, you need to manually add a new password to the root account after installation, because the root account does not enable password protection by default, if you do not re-authorize the root account password, many non-local connections will fail.

Method 1: Use the set password command. the steps for updating the PASSWORD are as follows:

C:> mysql-u rootmysql> set password for 'root' @ 'localhost' = password ('newpasswd '); mysql> set password for 'root' @ '%' = password ('newpasswd'); // optional

With the above settings, the root password is changed to newpasswd, and the root user's root password is set.

Method 2: Use mysqladmin

mysqladmin -u root password "newpass"

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 root  mysql> 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 mysql  mysql> UPDATE user SET password=PASSWORD("new password") WHERE user='root';  mysql> FLUSH PRIVILEGES;

In this simple way, the default password of the MySQL database is modified. after the default password is changed, you can perform more operations. I hope the content mentioned above will be helpful to you.

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.