MySQL添加新用户、为用户建立数据库、为新用户分配权限

登陆MySQLmysql

mysql -u root -p

添加新用户

容许本地 IP 访问 localhost, 127.0.0.1sql

create user 'test'@'localhost' identified by '123456';

容许外网 IP 访问数据库

create user 'test'@'%' identified by '123456';

刷新受权服务器

flush privileges;

为用户建立数据库

create database test DEFAULT CHARSET utf8 COLLATE utf8_general_ci;

为新用户分配权限

授予用户经过外网IP对于该数据库的所有权限ide

grant all privileges on `testdb`.* to 'test'@'%' identified by '123456';

授予用户在本地服务器对该数据库的所有权限code

grant all privileges on `testdb`.* to 'test'@'localhost' identified by '123456';

刷新权限ci

flush privileges;
相关文章
相关标签/搜索