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
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';
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';
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 'myuser'@'localhost';
In the above command,
For example, grant CREATE and INSERT permissions to all databases/tables:
mysql> GRANT CREATE, INSERT ON *.* TO 'myuser'@'localhost';
Verify the full permissions granted to the user:
mysql> SHOW GRANTS FOR 'myuser'@'localhost';
Grant full permissions to all databases/tables :
mysql> GRANT ALL ON *.* TO 'myuser'@'localhost';
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 'myuser'@'localhost';
5. The last important step in creating and setting up a MySQL user:
mysql> FLUSH PRIVILEGES;
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!