mysql版本问题,导致的mysql.user表下面的字段变成了authentication_string

在mysql5.*版本中使用

mysql> insert into user(host,user,password)values('localhost','lewis',password('123'));
ERROR 1054 (42S22): Unknown column 'password' in 'field list'

执行后报错  ERROR 1054(42S22) Unknown column 'password' in ‘field list’

错误的原因是 5.7版本下的mysql数据库下已经没有password这个字段了,password字段改成了authentication_string

所以,插入用户的正确的用法是
mysql> insert into user(host,user,authentication_string) values('localhost','lewis','123');
报错:ERROR 1364 (HY000): Field 'ssl_cipher' doesn't have a default value
出现错误的原因是mysql默认配置严格模式,该模式禁止通过insert的方式直接修改mysql库中的user表进行添加新用户。

解决方法是修改my.ini(Windows系统)或my.conf(Linux系统)配置文件,以linux系统为例将:
sql-mode=STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

修改成

sql-mode=NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
但是需要注意的是,既然mysql默认是禁止这种方法来创建用户是为了数据库的安全,所以我们也应该避免用插入的方式来创建用户。正确的创建用户的方式是:
create user '用户名'@'主机名' identified by '123';
flush privileges; //刷新权限

但必须注意,这样做有时也会出现一种问题:就是当你刚删完一个用户有要创建时

报错:ERROR 1396 (HY000): Opertion CREATE USER failed for 'lewis'@'localhost'
原因:你可能使用了delete语句从user中删除用户,这种行为因该被禁止.

不允许,直接修改表,否则会有各种麻烦.

这个bug的解释是:Assume the user is there, so drop the user
After deleting the user, there is need to flush the mysql privileges
Now create the user.(认为用户仍在这里,所以应该再用drop语句删除它,在delete 删除语句后,应该立马更新权限)
正确做法:
drop user 'lewis'@'localhost';
flush privileges;
create user 'lewis'@'localhost' identified by '123';
grant all privileges on test.* to lewis@localhost; //的到所有权限
flush privileges; //更新缓存

注意修改完表,flush privileges一下,否则会没读到缓存信息.

原文地址:https://www.cnblogs.com/nanfengnan/p/14725107.html