添加用户

1
2
3
4
mysql> use mysql;
mysql> insert into user
(host, user, authentication_string, select_priv, insert_priv, update_priv)
values('localhost', 'guest', md5('password123'), 'Y', 'Y', 'Y');
  • 得到报错信息:ERROR 1364 (HY000): Field 'ssl_cipher' doesn't have a default value
  • 该报错是因为MySQL默认配置了严格模式,该模式禁止通过insert的方式直接修改mysql库中的user表进行添加新用户,需要使用grant语句。
  1. 新增用户,’guest’为用户名 ,’localhost’为host,’password123’为密码

    1
    mysql> create user 'guest'@'localhost' identified by 'password123';
  2. 赋予权限 select, insert, update, delete, create, drop

    1
    2
    mysql> grant usage on *.* to 'guest'@'localhost' with grant option;
    mysql> grant select, insert, update, delete, create, drop on *.* to 'guest'@'localhost' with grant option;
  3. 重新载入授权表

    1
    mysql> flush privileges