# mysql 创建新用户并给授权指定的数据库权限 使用 root 管理员登陆 mysql ``` mysql -uroot -proot; ``` ## 创建新用户 ```sql -- 低版本数据库 create user '用户民'@'%' identified by '密码'; -- 高版本数据库 create user '用户名'@'%' identified with mysql_native_password by '密码'; ``` > '%' - 所有情况都能访问 > 'localhost' - 本机才能访问 > '111.222.33.44' - 指定 ip 才能访问 ## **修改密码:** ```sql alter user '用户名'@'%' identified by '密码'; ``` 这个时候访问,是除了默认生成information\_schema和test数据库,看不到任何其它的数据库信息 ## 赋予权限 ```sql -- 指定数据库 grant all privileges on 想授权的数据库.* to '用户名'@'%'; -- 全部数据库 grant all privileges on *.* to '用户名'@'%'; ``` > all 可以替换为 select,delete,update,create,drop ## 删除用户 ```sql delete from mysql.user where user='用户名'; ```