Note: In the case of CentOS 7, you can use MARIADB instead because the MySQL database has been removed from the default program list:
- Related commands for MARIADB database
Systemctl start mariadb #启动MariaDBsystemctl stop mariadb #停止MariaDBsystemctl restart mariadb # Restart Mariadbsystemctl Enable MARIADB #设置开机启动
mysql> CREATE USER ' myuser ' @ ' localhost ' identified by ' mypassword ';
Once the user is created, all account details, including encrypted passwords, permissions, and resource restrictions, are stored in a table named user, which is present in the special MySQL database.
If the host is not specified (at the back of the @), all IPs can be accessed;
- Verify that the account is created successfully by running the following command
SELECT host, user, password from mysql.user WHERE user= ' myuser ';
- Give MySQL user permissions
A new MySQL user does not have any access rights, which means that you cannot do anything in the MySQL database. You have to give the user the necessary privileges. The following are some of the available permissions:
All: All available permissions Create: Creates libraries, tables, and indexes Lock_tables: Lock table alter: Modify table Delete: Delete Table insert: Insert table or column select: Retrieve data for table or column Create_view: CREATE VIEW Show_ DATABASES: List database drop: Delete libraries, tables, and views
- Run the following command to give the "myuser" user specific permissions.
GRANT <privileges> on <database>.<table> to ' myuser ' @ ' localhost ';
The,<privileges> in the above command represents a comma-delimited list of permissions. If you want to assign permissions to any database (or table), use an asterisk (*) instead of the name of the database (or table).
SHOW GRANTS for ' myuser ' @ ' localhost ';
- Give all the permissions to all databases/tables:
GRANT all on * * to ' myuser ' @ ' localhost ';
REVOKE <privileges> on <database>.<table> from ' myuser ' @ ' localhost ';
FLUSH privileges;
Linux (CentOS 7 version) install MySQL (mariadb)