1. View all users in MySQL database
mysql> SELECT DISTINCT CONCAT(‘User: ‘‘‘,user,‘‘‘@‘‘‘,host,‘‘‘;‘) AS query FROM mysql.user;+---------------------------------+| query |+---------------------------------+| User: ‘root‘@‘10.4.3.10‘; || User: ‘root‘@‘10.4.32.15‘; || User: ‘root‘@‘10.4.35.16‘; || User: ‘root‘@‘::1‘; || User: ‘wang‘@‘localhost‘; || User: ‘root‘@‘localhost‘; || User: ‘bing‘@‘localhost‘; |+---------------------------------+7 rows in set (0.00 sec)
2. View the permissions of a specific user in the database
Mysql> Show grants for ' Wang ' @ ' localhost '; +-------------------------------------------------------------------------------------------------------------- -----+| Grants for [email protected] |+---- --------------------------------------------------------------------------------------------------------------- +| GRANT USAGE on *. Baobaowang ' @ ' localhost ' identified by PASSWORD ' *e9d0656c39ce83a05c11aadc5619f605f977c368 ' | | GRANT all Privileges "bing". * to ' wang ' @ ' localhost ' |+----------------- --------------------------------------------------------------------------------------------------+2 rows in Set ( 0.00 sec) Mysql> Show grants for ' root ' @ ' localhost '; +-------------------------------------------------------------------------------------------------------------- --------------------------+| Grants for [email protected] |+---------------------- --------------------------------------------------------------------------------------------------------------- ---+| GRANT all privileges on * * to ' root ' @ ' localhost ' identified by PASSWORD ' *96860be2538db7e343a108b32e0e54e64eede295 ' with GRANT OPTION | | Grant PROXY on "@" to "root" @ ' localhost ' with GRANT OPTION |+----------------------------------------------------------------------------------------------------------- -----------------------------+2 rows in Set (0.00 sec)
Mysql> SELECT * from Mysql.user where user= ' Wang ' \g *************************** 1. Row *************************** host:localhost User:baobaowang Password: *7295de9cf4976c84b2b2ac39620c255e885b16a0 select_priv:n insert_priv:n update_priv:n Delete_priv:n create_priv:n drop_priv:n reload_priv:n shutdown_priv:n Process_priv:n file_priv:n grant_priv:n references_priv:n index_priv:n Alter_priv:n show_db_priv:n super_priv:n create_tmp_table_priv:n Lock_tables_priv : N execute_priv:n repl_slave_priv:n repl_client_priv:n create_view_priv:n show_view_p Riv:n create_routine_priv:n alter_routine_priv:n create_user_priv:n event_priv:n Trigge R_priv:ncreate_tablespace_priv:n Ssl_type: ssl_cipher:x509_issuer:x509_subject:max_questions:0 max_updates:0 max_connections:0 max_user_connections:0 plugin:authentication_string:NULL1 Row in Set (0.00 SE C
3. Grant Usage
GRANT USAGE ON *.* TO ‘cuz‘@‘localhost‘ IDENTIFIED BY PASSWORD ‘*4585fa1158f37e2c1d7e41e4e309714a3fdd7826‘;GRANT ALL PRIVILEGES ON `cuz`.* TO ‘cuz‘@‘localhost‘;
Establish a user name that can only be logged on locally and cannot be manipulated cuz password for * * * * * * has been encrypted
And then the second sentence means, give this cuz user all permissions to the cuz database
Using the grant
The grant command is used to establish a new user, specify a user password, and increase user permissions. The format is as follows:
mysql> GRANT <privileges> ON <what>-> TO <user> [IDENTIFIED BY "<password>"]-> [WITH GRANT OPTION];
There are many things to fill in this command. Let's take a look at each of them and finally give some examples to get a sense of how they work together.
<privileges> is a comma-delimited list of MySQL user rights that you want to give. The permissions you can specify can be divided into three types:
*数据库/数据表/数据列权限:*Alter: 修改已存在的数据表(例如增加/删除列)和索引。Create: 建立新的数据库或数据表。Delete: 删除表的记录。Drop: 删除数据表或数据库。INDEX: 建立或删除索引。Insert: 增加表的记录。Select: 显示/搜索表的记录。Update: 修改表中已存在的记录。*全局管理MySQL用户权限:*file: 在MySQL服务器上读写文件。PROCESS: 显示或杀死属于其它用户的服务线程。RELOAD: 重载访问控制表,刷新日志等。SHUTDOWN: 关闭MySQL服务。*特别的权限:*ALL: 允许做任何事(和root一样)。USAGE: 只允许登录--其它什么也不允许做。
View all users and permissions in the MySQL database