Home  >  Article  >  Database  >  How to set login password in mysql

How to set login password in mysql

coldplay.xixi
coldplay.xixiOriginal
2020-09-29 14:41:2821847browse

Mysql method to set login password: 1. Use the SET PASSWORD command, the code is [mysql> set password for username@localhost = password ('new password')]; 2. Use the mysqladmin command.

How to set login password in mysql

##More related free learning recommendations: mysql tutorial(Video)

Mysql method to set login password:

Method 1: Use the SET PASSWORD command

First log in to MySQL.

Format: mysql> set password for username@localhost = password('new password');

Example: mysql> set password for root@localhost = password('123');

Method 2: Use mysqladmin

Format: mysqladmin -u username -p old password password new password

Example: mysqladmin -uroot -p123456 password 123

How to set login password in mysql

Method 3: Use UPDATE to directly edit the user table

First log in to MySQL.

mysql> use mysql;

mysql> update user set password=password('123') where user='root' and host='localhost';

mysql> ; flush privileges;

Method 4:Use the GRANT statement mysql>grant all on *.* to 'root'@'localhost' IDENTIFIED BY 'your password'with grant option ;mysql> ;flush privileges;

Method 5:When you forget the root password or initialization password, you can do this

Take windows as an example:

1. Shut down the running MySQL service.

2. Open the DOS window and go to the mysql\bin directory.

3. Enter mysqld --skip-grant-tables and press Enter. --skip-grant-tables means to skip the permission table authentication when starting the MySQL service.

4. Open another DOS window (because the DOS window just now cannot be moved) and go to the mysql\bin directory.

5. Enter mysql and press Enter. If successful, the MySQL prompt > will appear.

6. Connect to the permission database: use mysql;.

6. Change password: update user set password=password("123") where user="root"; (don't forget to add the semicolon at the end).

7. Refresh privileges (required step): flush privileges;.

8. Quit.

9. Log out of the system, re-enter, and log in using the username root and the new password 123 you just set.

6. After setting up, you can test whether it is successful. Click on the connection test. If it prompts success, it means the setting is complete.

How to set login password in mysql

The above is the detailed content of How to set login password in mysql. 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