Home  >  Article  >  Database  >  How to modify user in mysql

How to modify user in mysql

WBOY
WBOYOriginal
2022-01-20 14:39:076603browse

Method: 1. Use the "RENAME USER" statement to modify the user name, the syntax is "RENAME USER old user name TO new user name"; 2. Use the "SET PASSWORD" statement to modify the user password, the syntax is "SET PASSWORD=PASSWORD (new user password)".

How to modify user in mysql

The operating environment of this tutorial: windows10 system, mysql8.0.22 version, Dell G3 computer.

How to modify mysql user

Modify user account

You can use the RENAME USER statement to modify one Or multiple existing MySQL user accounts.

Syntax format:

RENAME USER <旧用户> TO <新用户>

The syntax description is as follows:

: MySQL user account that already exists in the system.

: New MySQL user account.

  • You should pay attention to the following points when using the RENAME USER statement:

  • The RENAME USER statement is used to rename the original MySQL account.

  • If the old account does not exist in the system or the new account already exists, an error will occur when this statement is executed.

To use the RENAME USER statement, you must have UPDATE permission on the MySQL database in MySQL or global CREATE USER permission.

Use the RENAME USER statement to change the user name james to jack, and the host is localhost. The input SQL statement and execution process are as follows.

mysql> RENAME USER james@&#39;localhost&#39;
    -> TO jack@&#39;localhost&#39;;
Query OK, 0 rows affected (0.03 sec)

In the Windows command line tool, use jack and password tiger to log in to the database server, as shown below.

C:\Users\USER>mysql -h localhost -u jack -p
Enter password: *****
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 5.7.20-log MySQL Community Server (GPL)
Copyright (c) 2000, 2017, 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 &#39;help;&#39; or &#39;\h&#39; for help. Type &#39;\c&#39; to clear the current input statement.

You can use the SET PASSWORD statement to modify a user's login password.

[test_user_new2] is the new password

set password=password(&#39;test_user_new2&#39;);

How to modify user in mysql

How to modify user in mysql

Recommended learning: mysql video tutorial

The above is the detailed content of How to modify user 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