mysql新建用户

1326人浏览 / 0人评论 / 添加收藏

添加新用户
允许本地 IP 访问 localhost, 127.0.0.1 copy

  1. create user '用户名'@'localhost' identified by '密码';
  2. create user '用户名'@'%' identified by '密码';  

刷新授权

  1. flush privileges;

为用户创建数据库

  1. create database test DEFAULT CHARSET utf8 COLLATE utf8_general_ci;

为新用户分配权限
授予用户通过外网IP对于该数据库的全部权限

  1. grant all privileges on \`数据库名\`.* to 'test'@'%' identified by '密码';
  2. 如果是mysql8以上这句话要改为
  3. grant all privileges on `数据库名`.* to '用户名'@'localhost' WITH GRANT OPTION;

授予用户在本地服务器对该数据库的全部权限

  1. grant all privileges on `数据库名`.* to '用户名'@'localhost' identified by '密码'; 
  2. 如果是mysql8以上这句话要改为
  3. grant all privileges on `数据库名`.* to '用户名'@'localhost' WITH GRANT OPTION;

刷新权限

  1. flush privileges;  

退出 root 重新登录

用新帐号 test 重新登录,由于使用的是 % 任意IP连接

全部评论