mysql5.7 users to create, authorize, remote login

1, add a user
different from previous versions, MySQL5.7 mysql.user table no password field, which turned into a authentication_string;
here we use the command to create a user:

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


Such as creating a test user, the password is test123, you can log on remotely:

 create user 'test'@'%' identified by 'test123'


username - The name you will create,
Host - specify that users can log on which host, "localhost" here, means that the user can only log on locally, not remotely log in on another machine, if you want to remote login, it will "localhost" to "%", he said can log on from any computer; you can also specify a machine can remotely log;
password - the user's login password, the password can be empty, if empty the user can log in without a password server.

2, delete the user
if the user creates a wrong, it must support the deletion, use the command:

DROP USER 'username'@'host';

3, authorized
authorized test users have permission to testDB a certain part of the database:

grant select,update on testDB.* to test@'%' identified by 'test123';


All authorized test users operating authority testDB database:

grant all privileges on testDB.* to 'test'@'%' identified by 'test123';


Authorized users have certain rights to all test databases:

grant select,delete,update,create,drop on *.* to 'test'@'%' identified by 'test123';


privileges - a user's operation authority, such as select, delete, update, create, drop etc. (detailed list self Baidu), if all granted permission to use all (second reference Authorization); represents% of all non-local host authorization, not including localhost.

Case:

. Mysql> GRANT ALL privileges ON test * TO usr @ '%' IDENTIFIED BY 'password' WITH GRANT OPTION; coexistence of three character classes to set a password when #

Query OK, 0 rows affected, 1 warning (0.01 sec)

 

mysql> flush privileges; # refresh authority table

Query OK, 0 rows affected (0.01 sec)

 

[root@instance-ozyu8y37 ~]# mysql -ugeek -p

Enter password: 

ERROR 1045 (28000): Access denied for user 'geek' @ 'localhost' (using password: YES) # error saying in geek user password is required to log on locally, and I just did not set up a local login, so enter the root settings

[root@instance-ozyu8y37 ~]# mysql -uroot -p

Enter password: 

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 1261

Server version: 5.7.24 MySQL Community Server (GPL)

 

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

 

Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.

 

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

 

mysql> GRANT ALL privileges ON test.* TO usr@'localhost' IDENTIFIED BY 'password' WITH GRANT OPTION;​

Query OK, 0 rows affected, 1 warning (0.00 sec)

 

mysql> flush privileges;

Query OK, 0 rows affected (0.00 sec)

Exit and re-created with a new user login is successful

Guess you like

Origin blog.csdn.net/weixin_41808843/article/details/88979786