MySQL command and method for modifying and setting the root password

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

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,

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 server5.1\ Bin>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 Files \ mysql server5.1\ Bin>Mysqladmin-U Root-P Password123456Enter Password: C: \ Program Files \ mysql server5.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 server5.1\ Bin>Mysqladmin-U Root-P123456 password rootc: \ Program Files \ mysql server5.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  Changedmysql  >   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 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 SetPassword='' Where User='Root';

That's all.

Use the set password command to modify the MySQL Root Password

MySQL> UseMySQLDatabaseChangedmysql> SetPasswordFor '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.

Note: PhP website development tutorial -leapsoul.cn All Rights Reserved. Please indicate the original source and this statement in the form of a link during reprinting. Thank you.

 

 

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.