0%

mysql 用户与权限

为不同的用户分配不同的权限

用户

创建用户

1
2
create user 'username' @'ip address' identified by 'password'
-- set ip address as %: user can log in from any address( not include localhost( 127.0.0.1 ) )

权限

分配权限给用户

1
2
3
4
grant all privileges on databasename.tablename to 'username'@'ip address'
-- all can be replaced by other sql operations like select,update etc
-- tablename can be replaced by *
-- we can also append 'identified by new password' to set a different for this user

授权外网链接

1
2
cd /etc/mysql/mysql.conf.d
sudo vim mysqld.cnf

注释掉 bind-address = 127.0.0.1