mysql-permissions, transactions

1. Permissions

MySQL has a root user by default, but this user has too much authority and is generally only used when managing the database. If you want to connect to the MySQL database in the project, it is recommended to create a new user with less privileges to connect.

Enter the following command in MySQL command line mode to create a new user for MySQL:

1
CREATE USER username IDENTIFIED BY 'password' ;

The new user is created, but if you log in with this user at this moment, an error will be reported, because we have not assigned the corresponding permissions to this user. The command to assign permissions is as follows:

1
GRANT ALL PRIVILEGES ON *.* TO 'username' @ 'localhost' IDENTIFIED BY 'password' ;

Grants the username user all privileges on all databases.

If it is found that the permissions just given are too large at this time, if we just want to grant it permissions on a certain database, then we need to switch to the root user to revoke the permissions just now and re-authorize:

1
2
EVOKE ALL PRIVILEGES ON *.* FROM 'username' @ 'localhost' ;
GRANT ALL PRIVILEGES ON wordpress.* TO 'username' @ 'localhost' IDENTIFIED BY 'password' ;

You can even specify that this user can only execute select and update commands:

1
GRANT SELECT , UPDATE ON wordpress.* TO 'username' @ 'localhost' IDENTIFIED BY 'password' ;

In this way, log in to MySQL with username again, only the wordpress database is visible to it, and if you only grant it select permission, it cannot execute the delete statement.

In addition, whenever the permissions are adjusted, it is usually necessary to execute the following statement to refresh the permissions:

1
FLUSH PRIVILEGES ;

Delete the user you just created:

1
DROP USER username@localhost;

Looking at the above commands carefully, you can find that whether it is authorization or revocation, you must specify the host of the response (that is, the content after the @ symbol), because the above passing commands are actually operating the user table in the mysql database, you can use Use the following command to view the corresponding user and corresponding host

1  SELECT  User , Host FROM  user ;

  

Guess you like

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