MySQL database add user, delete user and authorization

1. Install the mysql database

2. Log in to mysql

$ mysql -uroot -proot

3. Create a user

mysql> CREATE USER 'username'@'host' IDENTIFIED BY 'password';

example:

mysql> CREATE USER 'dog'@'localhost' IDENTIFIED BY '123456';
mysql> CREATE USER 'dog2'@'localhost' IDENTIFIED BY '';

PS:

username - the username you will create,

host - specifies the host on which the user can log in. The "localhost" here means that the user can only log in locally and cannot log in remotely on another machine. If you want to log in remotely, change "localhost" to It is "%", which means that you can log in on any computer; you can also specify that a certain machine can log in remotely;

password - the user's login password, the password can be empty, if it is empty, the user does not need a password to log in to the server.

4. Authorization

mysql> GRANT privileges ON databasename.tablename TO 'username'@'host'

example:

mysql> GRANT SELECT, INSERT ON mq.* TO 'dog'@'localhost';

PS:

privileges - user's operating privileges, such as SELECT, INSERT, UPDATE, etc. (see the end of this article for a detailed list). If you want to grant all privileges, use ALL.;

databasename - database name,

tablename-table name, if you want to grant the user the corresponding operation permissions on all databases and tables, you can use * , such as *.* .

5. Create a user and authorize at the same time

mysql>  grant all privileges on mq.* to test@localhost identified by '1234';

This creates the test user (password 1234) and gives him all permissions to all tables under the mq database

6. Refresh permissions to make the settings take effect

mysql> flush privileges;

 

Guess you like

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