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

How to create a user in MySQL

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

Share

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

This article shows you how to create a user in MySQL. The content is concise and easy to understand. It will definitely brighten your eyes. I hope you can gain something through the detailed introduction of this article.

1. Create a user using a CREATE USER statement

CREATE USER [IDENTIFIED BY [PASSWORD] 'password'] [, user [IDENTIFIED BY [PASSWORD]' password']]

User: specify to create a user account in the format of user_name'@'host_name, where user_name is the user name and host_name host name

IDENTIFIED BY clause: used to specify the user password. A new user may not have an initial password. If the user does not set a password, this clause can be omitted.

PASSWORD 'password':PASSWORD means to set the password with a hash value, which is optional. If the password is an ordinary string, the PASSWORD keyword is not required.' Password' indicates the password the user uses when logging in, which needs to be enclosed in single quotation marks.

two。 Create a new user using the INSERT statement

You can use the INSERT statement to add the user's information to the mysql.user table, but you must have INSERT permission on the mysql.user table. Usually the INSERT statement adds only the values of the Host, User, and authentication_string fields.

The password field in the user table of MySQL 5.7has changed from Password to authentication_string. If you are using a version prior to MySQL 5.7, replace the authentication_string field with Password.

INSERT INTO mysql.user (Host, User, authentication_string, ssl_cipher, x509_issuer, x509_subject) VALUES ('hostname',' username', PASSWORD ('password'),')

3. Create a new user using the Grant statement

Although both CREATE USER and INSERT INTO statements can create ordinary users, it is not convenient to grant user permissions in both ways. So MySQL provides the GRANT statement.

GRANT priv_type ON database.table TO user [IDENTIFIED BY [PASSWORD] 'password']

The priv_type parameter indicates the permissions of the new user

The database.table parameter indicates the scope of permissions of the new user, that is, you can only use your own permissions on the specified database and table

The user parameter specifies the account number of the new user, which consists of user name and host name.

IDENTIFIED BY keyword is used to set the password

The password parameter represents the password of the new user.

The above is how to create a user in MySQL. Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.

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