Home >Database >Mysql Tutorial >How to set password in mysql without password

How to set password in mysql without password

coldplay.xixi
coldplay.xixiOriginal
2020-10-26 13:54:598753browse

Mysql password-less setting method: 1. Use mysqladmin to complete [shell> mysqladmin -u root password "newpwd"]; 2. Use the SET PASSWORD command in mysql to complete.

How to set password in mysql without password

Mysql passwordless method to set password:

Method one: The simplest The method is also the method prompted by the system after installing mysql. Use mysqladmin to complete.

shell> mysqladmin -u root password "newpwd"

shell> mysqladmin -u root -h host_name password "newpwd"The double quotation marks after password are not necessary, but if the password contains spaces or some special symbols, quotation marks are required.

Method 2: Use the SET PASSWORD command in mysql to complete. Note that the PASSWORD() function must be used to encrypt the set newpwd, otherwise directly ='newpwd' will not take effect. However, if you use method 1 to set the password with mysqladmin password or GRANT, you do not need to use the PASSWORD() function because they have automatically called this function. shell> mysql -u root

mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('newpwd');
mysql> SET PASSWORD FOR 'root'@'host_name' = PASSWORD('newpwd');

Method 3:Set password directly through UPDATE user tableshell> mysql -u root

mysql> UPDATE mysql.user SET Password = PASSWORD('newpwd')
-> WHERE User = 'root';
mysql> FLUSH PRIVILEGES;

Update More related free learning recommendations: mysql tutorial(video)

The above is the detailed content of How to set password in mysql without password. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Related articles

See more