Mysql command and method for modifying and setting the root password

Source: Internet
Author: User
Tags mysql commands mysql update php website mysql command line

 

Mysql database is an essential combination for PHP website development. Generally, PHP connects to Mysql through the root user name and password. The initial root password is blank during Mysql installation, when installing and using the PHP open-source system, you must enter the username and password for connecting to the Mysql database. When you forget the Mysql root Password or do not set the Mysql root Password, you must modify or set the Mysql root password. This is also a big problem for beginners of PHP. In fact, there are many ways to modify the Mysql root Password. You can use the Mysql tool, you can also use the Mysql command to change the root password.

Preparations

Before using Mysql tools or Mysql commands to change the root password, make sure that you have started the Mysql service. If you have not started the Mysql service, enter


Net start mysql

You can.

Mysql common tools for modifying the root password

Use phpmyadmin to change the root passwordHow do I install and configure phpmyadmin?

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,


Use phpmyadmin to change the root password of mysql

Note that phpmyadmin does not allow empty Logon of Mysql's root password by default. If you accidentally select an empty password on the password modification page, you need to modify the phpmyadmin configuration file so that you can log on to phpmyadmin again to change the mysql root Password. Next time, I will explain how to modify it.

Use the Mysql service configuration tool to change the root password

During Mysql5 installation, there is a service Configuration tool that can be used to set and modify the root password, that is, Mysql Server Instance Configuration. For detailed Configuration process, refer to PHP environment setup: install and configure the PHP + Apache + Mysql environment in Windows 7.

Command description for changing the root password of Mysql

In addition to using phpmyadmin and Mysql service configuration tools to change the root password, you can also use the Mysql password change command to change the root password.

There are two methods to access the Mysql database command line:

Method 1: the Mysql command line client is included in the Mysql Start Menu. You only need to enter the root password.

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 Files \ MySQL Server 5.1 \ bin> mysql-u root-p
Enter 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 Files \ MySQL Server 5.1 \ bin> mysqladmin-u root-p password 123456
Enter password:
C: \ Program Files \ MySQL Server 5.1 \ bin> 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 you have set the Mysql root Password, You need to modify it and enter the Mysql command line mode, enter


C: \ Program Files \ MySQL Server 5.1 \ bin> mysqladmin-u root-p123456 password root
C: \ Program Files \ MySQL Server 5.1 \ bin> mysql-u root-proot

You can.

Knowledge Point: The two commands mysqladmin.exeand mysql.exe are used here. The command format for mysqladmin to change the password 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.

The format of the mysql Command is similar to that of the mysqladmin command. It is mainly used to enter the correct user name and password and enter the Mysql command line mode. The format is as follows:


Mysql-u root-p [password]

If you do not Enter the password, the Enter password prompt will appear after you press Enter. If the root password is blank, you do not need to Enter the password. If the Enter password prompt appears, press Enter.

Use the update command to modify the Mysql root Password

You can use the Mysql update command to modify the old root password or set the root password to null. If you use the update command to change the root password, you need to use the built-in Mysql encryption function PASSWORD (string), which is used to encrypt a plaintext PASSWORD and cannot be decrypted. set the password in the user (user permission table.

Use the update command to change the root password as follows:


Mysql> use mysql
Database changed
Mysql> update user set password = PASSWORD ('000000') 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 that after using update, you need to enter the flush privileges statement. Otherwise, the PASSWORD change command will not take effect. If you need to set the Mysql root PASSWORD to null, you do not need to use the PASSWORD function.


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

That's all.

Use the set password command to modify the Mysql root password


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 do not need to flush privileges; to make the command to change the password take effect. When using the set password command to modify the root password, be sure to perform the operation with caution, which is prone to errors and cause logon failure,

At this point, the commonly used methods and commands for changing the root password of Mysql have been introduced. It is important to say that the root password of Mysql is very important. If the root password is forgotten or stolen, it may cause serious consequences. It is recommended that you rename the root user or create another user in the user (user permission table) to grant the usual minimum permission configuration to ensure the security of the website, it is also convenient to reset or change the root password in the future.

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.