13.4 MySQL User management
- Create a user and authorize
[[email protected] ~]# mysql -uroot -p‘taoyuan‘ //登录mysql> grant all on *.* to ‘user1‘@‘172.0.0.1‘ identified by ‘123456‘;#创建user用户并授予其所有权限“*.*”(通配符)#第一个*表示db_name;第二个*表示tb_name#同时指定其来源IP127.0.0.1(即,只可通过此IP登录)#此处可以使用通配符%,代表所有IP(一般不使用)#identified by :设定密码#quit 退出[[email protected] ~]# mysql -uuser1 -p123456 -h127.0.0.1
Sign in with a socket
#登录root用户mysql> grant all on *.* to ‘user1‘@‘localhost‘ identified by ‘123456‘;Query OK, 0 rows affected (0.01 sec)#授权localhost#登录[[email protected] ~]# mysql -uuser1 -p123456
Note: because the specified login host is localhost, the user uses the local mysql.socket file by default (listening) and does not need to specify an IP to log on.
- Authorization for specific permissions
[[email protected] ~]# mysql -urootmysql> show grants;#查看当前用户的权限mysql> show grants for [email protected]‘127.0.0.1‘;#查看指定用户的权限mysql> GRANT SELECT, INSERT, UPDATE ON `db1`.* TO ‘user2‘@‘192.168.1.15‘; Query OK, 0 rows affected (0.01 sec)#在不知道密码的情况下,可以直接用show grants命令进行复制,修改ip地址 增加。
MySQL user management, common SQL statements, MySQL database backup recovery