Home > Database > Mysql Tutorial > Detailed introduction to the method of creating new users in mysql under linux

Detailed introduction to the method of creating new users in mysql under linux

黄舟
Release: 2017-03-20 14:04:02
Original
1602 people have browsed it

This article mainly introduces the method of creating new users under linuxmysql. It is very good and has reference value. Friends who need it can refer to it

1. Log in to the MySQL server as root.

$ mysql -u root -p
Copy after login

When the verification prompt appears, enter the password for the MySQL root account.

2. Create a MySQL user

Use the following command to create a user whose username and password are divided into "username" and "userpassword".

mysql> CREATE USER ‘username'@'localhost' IDENTIFIED BY ‘userpassword';
Copy after login

Once a user is created, all account details including encrypted passwords, permissions and resource restrictions will be stored in a table named user, which exists in the special database mysql inside.

3. Run the following command to verify whether the account is created successfully

mysql> SELECT host, user, password FROM mysql.user WHERE user='myuser';
Copy after login

4. Grant MySQL user permissions

Create a new The MySQL user does not have any access rights, which means that you cannot perform any operations in the MySQL database. You have to give the user the necessary permissions. Here are some of the available permissions:

ALL: All available permissions

CREATE: Create libraries, tables, and indexes

LOCK_TABLES: Lock tables

ALTER : Modify table

DELETE: Delete table

INSERT: Insert table or column

SELECT: Retrieve table or column data

CREATE_VIEW: Create view

SHOW_DATABASES: List databases

DROP: Delete libraries, tables and views

Run the following command to give the "myuser" user specific permissions.

<mysql> GRANT<privileges>ON <database>.<table> TO &#39;myuser&#39;@&#39;localhost&#39;;
Copy after login

In the above command, represents a comma-separated list of permissions. If you want to grant permissions to any database (or table), use an asterisk (*) in place of the database (or table) name.

For example, grant CREATE and INSERT permissions to all databases/tables:

mysql> GRANT CREATE, INSERT ON *.* TO &#39;myuser&#39;@&#39;localhost&#39;;
Copy after login

Verify the full permissions granted to the user:

mysql> SHOW GRANTS FOR &#39;myuser&#39;@&#39;localhost&#39;;
Copy after login

Grant full permissions to all databases/tables :

mysql> GRANT ALL ON *.* TO &#39;myuser&#39;@&#39;localhost&#39;;
Copy after login

You can also delete the user’s existing permissions. Use the following command to revoke the existing permissions of the "myuser" account:

mysql> REVOKE <privileges> ON <database>.<table> FROM &#39;myuser&#39;@&#39;localhost&#39;;
Copy after login

5. The last important step in creating and setting up a MySQL user:

mysql> FLUSH PRIVILEGES;
Copy after login

This is it The changes take effect. The MySQL user account is now ready for use.

The above is the detailed content of Detailed introduction to the method of creating new users in mysql under linux. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template