Commands and methods for setting the root password in MySQL database

Source: Internet
Author: User
Tags configuration php mysql update mysql command line phpmyadmin

We all know that the usual PHP connection MySQL is connected by the root username and password, by default, when the MySQL installation of the root initial password is empty, when installing the use of PHP open source system, you need to fill in the MySQL database user name and password, At this point when you forget the root password of MySQL or not set up the root password of MySQL, you have to modify or set the root password of MySQL, this problem is a big problem for beginners in PHP, in fact, there are many ways to modify the root password of MySQL, You can use the MySQL tool, or you can use MySQL to change the root password of the command to achieve.

Preparatory work

Before using the MySQL-related tool or the MySQL command to modify the root password, make sure that you have started the MySQL service, and if you do not start the MySQL service, enter it in DOS mode


net start MySQL

Can.

MySQL Common tool to modify root password

Use phpMyAdmin to change the root password how to install configuration phpMyAdmin?

Using phpMyAdmin to change the root password of MySQL is very convenient, installation configuration phpMyAdmin after the first login management interface, click on the right to change the password link, enter the MySQL root new password you want to modify, finally click to execute,

Use phpMyAdmin to modify the root password of MySQL

Use phpMyAdmin to modify the root password of MySQL

Note here that phpMyAdmin default is not allow MySQL root default password is empty login, if you accidentally choose a blank password in the Change password interface, you need to modify the phpMyAdmin configuration file to re-login phpMyAdmin to implement the change MySQL The root password function. How to modify the next time I will explain.

Using the MySQL service Configuration tool to modify the root password

MYSQL5 installation process has a service Configuration tool can be used to set up and modify the root password, that is, MySQL Server Instance configuration, the specific process refer to the PHP environment build: Windows 7 Installation configuration php+apache+ MySQL Environment tutorial article.

MySQL change root password command description

In addition to using the phpMyAdmin, MySQL service Configuration tool to modify the root password, you can change the root password by using the MySQL password change command.

There are two ways to enter the MySQL database command line mode:

Mode one: In the MySQL Start menu contains the MySQL command line client, just click enter root password to enter.

Mode two: In DOS mode (CMD mode) Navigate to the MySQL installation directory in the subdirectory bin, call Mysql.exe to enter, i.e.


C:\Program files\mysql\mysql Server 5.1\bin>mysql-u root-p

Enter Password: ******

Use the Mysqladmin.exe command to modify the root password of MySQL

General MySQL root default password is empty, if you have not set the root password before using the Mysqladmin command, you can use the following mysqladmin command to modify the root password


C:\Program files\mysql\mysql Server 5.1\bin>mysqladmin-u root-p password 123456

Enter Password:

C:\Program files\mysql\mysql Server 5.1\bin>mysql-u root-p123456

As described above using mysqladmin to first modify the root's default password, enter password enter, and then use the Mysql.exe command to enter root and its password to enter the MySQL command line.

I use the red font, modify the success!

If you have set the root password for MySQL and now need to modify it and go to MySQL command line mode, enter


C:\Program files\mysql\mysql Server 5.1\bin>mysqladmin-u root-p123456 Password root

C:\Program files\mysql\mysql Server 5.1\bin>mysql-u root-proot

Can.

Knowledge Point: Here is used to the MySQL comes with two commands mysqladmin.exe and mysql.exe,mysqladmin change the password command format as follows


Mysqladmin-u Root-p[oldpass] Password newpass

Note Oldpass (old password) optional, if the root default password is empty, you do not need to enter, if you need to change the old password, please note that the old password and-p do not have a space, otherwise will be error, the other password and newpass (new password) separated by a space.

MySQL command is similar to the mysqladmin command format, mainly used to enter the correct user name and password after entering the MySQL command line mode, the format is as follows

Mysql-u Root-p[password]

If you do not enter password, the Enter password prompt will appear after the carriage return. If the root password is empty, you do not need to enter password, the Enter password prompt and enter.

Use the update command to modify the root password of MySQL

Use the MySQL update command to either modify the root's old password or set the root password to NULL, if you use the Update command to change the root password, you need to use MySQL's own cryptographic function password (string), This function encrypts a plaintext password and is not decrypted, specifically for setting the password in the Mysql.user (User Rights table).

The following method is used to modify the root password using the update command


mysql> use MySQL

Database changed

mysql> Update user Set Password=password (' 123456 ') where user= ' root ';

Query OK, 0 rows Affected (0.00 sec)

Rows matched:1 changed:0 warnings:0

mysql> flush Privileges;

Query OK, 0 rows Affected (0.00 sec)

Note After using the update, you need to further enter the flush privileges; statement, otherwise the Change Password command operation will not take effect, if you need to set the root password of MySQL is empty, you do not need to use the password function, directly


Update user set password= ' where user= ' root ';

Can be, the other same.

Use the Set password command to modify the root password of MySQL


mysql> use MySQL

Database changed

mysql> set password for ' root ' @ ' localhost ' =password (' LEAPSOULCN ');

You also need to use the password function when using the Set password command, but you do not need to flush privileges; You can make the command operation that modifies the password take effect. When you use the Set password command to modify the root password, be sure to be cautious, error-prone and unable to log in.

At this point, the common MySQL change root password method and command is finished, it should be said that the root password of MySQL is very important, if you forget the root password or stolen, will have serious consequences, it is recommended to rename the root user, Or create a new user in the User Permissions table, giving the usual minimum permissions configuration to ensure the security of the site, and to reset or change the root password in the future.

Transferred from: http://www.6a8a.com/2011/Mysql_0314/489.html

Commands and methods for setting the root password in MySQL database

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.