Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the ways to change the database password

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly explains "what are the ways to change the database password". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's way of thinking. Let's study and learn "what are the ways to change the database password?"

1. Forget the root password

It is quite common to forget the root password, especially when the test environment you built has been out of date for a long time, so it is easy to forget the password set at that time. The common method at this time is to skip permission verification, then change the root password, and then enable permission authentication. Take MySQL version 5.7 as an example to briefly describe the main process:

First modify the configuration file, adding a sentence to the [mysqld] section: skip-grant-tables, and the purpose of this parameter is to skip permission verification. Then restart the database, and after the database starts again, we can log in to the database directly without a password to change the password.

Modify the root password [root@host ~] # mysql Welcome to the MySQL monitor in # skip-grant-tables mode. Commands end with; or\ g. Your MySQL connection id is 16 Server version: 5.7.23-log MySQL Community Server (GPL) Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or'\ h' for help. Type'\ c'to clear the current input statement. Mysql > update mysql.user set authentication_string = password ('xxxxxx') where user =' root' and host = 'localhost'; Query OK, 0 rows affected, 1 warning (0.00 sec) Rows matched: 1 Changed: 0 Warnings: 1 mysql > flush privileges; Query OK, 0 rows affected (0.01 sec)

After changing the root password, remove the skip-grant-tables parameter again, and then restart the database.

two。 Several methods of changing password

Apart from forgetting your password, there may be other situations where you need to change your password, so you can change your password in a normal way. Taking MySQL version 5.7 as an example, this paper introduces several common methods of changing passwords.

Modify using alter user

For example, if you want to change the password of the testuser account, we can log in using the root account, and then execute the alter user command to change the password of the testuser account.

Mysql > alter user' testuser'@'%' identified by 'Password1'; Query OK, 0 rows affected (0.01 sec) mysql > flush privileges; Query OK, 0 rows affected (0.00 sec)

Use the SET PASSWORD command

Use SET PASSWORD to change the password command in the format of SET PASSWORD FOR 'username'@'host' = PASSWORD (' newpass'); you can also use the root account to change the password of other accounts.

Mysql > SET PASSWORD FOR 'testuser'@'%' = PASSWORD (' Password2'); Query OK, 0 rows affected, 1 warning (0.00 sec) mysql > flush privileges; Query OK, 0 rows affected (0.00 sec)

Use mysqladmin to change the password

Use the mysqladmin command to change the account password format to mysqladmin-u username-p old password password new password

[root@host] # mysqladmin-utestuser-pPassword2 password Password3 mysqladmin: [Warning] Using a password on the command line interface can be insecure. Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety. [root@host] # mysql-utestuser-pPassword3 mysql: [Warning] Using a password on the command line interface can be insecure. Welcome to the MySQL monitor. Commands end with; or\ g. Your MySQL connection id is 2388 Server version: 5.7.23-log MySQL Community Server (GPL) Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or'\ h' for help. Type'\ c'to clear the current input statement. Mysql >

Direct update user table

In fact, all the account information of MySQL is stored in the mysql.user table, and we can also change the password directly through the update user table.

Mysql > update mysql.user set authentication_string = password ('Password4') where user=' testuser' and host='%'; Query OK, 1 row affected, 1 warning (0.06 sec) Rows matched: 1 Changed: 1 Warnings: 1 mysql > flush privileges; Query OK, 0 rows affected (0.01 sec) # 5.6 and previous versions update mysql.user set password=password ('new password') where user=' username 'and host='host';3. Set up login-path local quick login

In order to prevent the password from being exposed and forgotten, we can also set up login-path to quickly log in locally without typing a password.

Login-path is a new feature supported by MySQL 5.6. With the help of the mysql_config_editor tool, the authentication information for logging in the MySQL service is encrypted and saved in the .mylogin.cnf file (the default is in the user's home directory). The MySQL client tool can log in quickly by reading the encrypted file and connecting to MySQL.

Suppose we want to configure a root account to log in quickly and locally, we can do this:

# enter the root password [root@host] # mysql_config_editor set-- login-path=root-uroot-hlocalhost-p-P3306 Enter password: # after completing the configuration, you can log in to [root@host ~] # mysql-- login-path=root Welcome to the MySQL monitor using login-path. Commands end with; or\ g. Your MySQL connection id is 2919 Server version: 5.7.23-log MySQL Community Server (GPL) Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or'\ h' for help. Type'\ c'to clear the current input statement. Mysql > Thank you for your reading. The above is the content of "what are the ways to change the database password". After the study of this article, I believe you have a deeper understanding of the way to change the database password, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report