Linux (CentOS 7 version) install mysql (mariadb)

Note: In case of CentOS 7 version, since the MySQL database has been removed from the default program list, you can use mariadb instead:

  • install command
yum install mariadb-server mariadb 
  • Commands related to mariadb database
systemctl start mariadb  #启动MariaDB
systemctl stop mariadb  #停止MariaDB
systemctl restart mariadb  #重启MariaDB
systemctl enable mariadb #Set boot up
  • create user
mysql> CREATE USER 'myuser'@'localhost' IDENTIFIED BY 'mypassword';

   Once a user is created, all account details including encrypted passwords, permissions, and resource restrictions are stored in a table called user, which exists in a special database called mysql.

    If no host is specified (the content after @), all IPs can be accessed;

 

  • Run the following command to verify that the account was created successfully
SELECT host, user, password FROM mysql.user WHERE user='myuser';
  • Grant MySQL User Privileges

   A newly created 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 available permissions:

ALL: all available permissions
CREATE: Create libraries, tables and indexes
LOCK_TABLES: lock tables
ALTER: modify table
DELETE: delete table
INSERT: Insert into a table or column
SELECT: Retrieve data from a table or column
CREATE_VIEW: create a view
SHOW_DATABASES: List databases
DROP: drop libraries, tables and views
  • Run the following command to give the "myuser" user specific permissions.
GRANT <privileges> ON <database>.<table> TO 'myuser'@'localhost';

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

 

  • Verify the full permissions granted to the user:

SHOW GRANTS FOR 'myuser'@'localhost';
  • Grant full permissions to all databases/tables:
GRANT ALL ON *.* TO 'myuser'@'localhost';
  • Use the following command to revoke the existing privileges of the "myuser" account:

REVOKE <privileges> ON <database>.<table> FROM 'myuser'@'localhost';
  • The last important step in creating and setting up a MySQL user:

FLUSH PRIVILEGES;

  

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324887758&siteId=291194637