mysql5.7升级到mysql8.0遇到的问题


今天把博客迁移了服务器,顺便把mysql5.7升级到了mysql8.0,,过程还算顺利,mysql上只碰到了两个问题,记录一下。

一、登录问题

mysql8.0建好后发觉navcat12登录不上去,提示ERROR 2059 (HY000): Authentication plugin 'caching_sha2_password' cannot be loaded。查了下发觉mysql又改变了登录认证方式。新的默认的登录是采用caching_sha2_password方式,而将原来的登录方式放到了mysql_native_password方式中。

mysql5.7中我们创建用户的语句是这样的:

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

在mysql8.0中这样创建的就是采用caching_sha2_password方式登录认证的用户,要在8.0中恢复原来的密码登录方式,需要将语句变为:

1
create user test@localhost identified with mysql_native_password by '123456';

相应的,对于已经创建的用户,修改其登录方式和密码:

1
alter user test@localhost identified with mysql_native_password by '123456';

二、datetime问题

将mysql5.7的结构和数据导入mysql8.0时,发生datetime默认值错误的问题。查看了下sql语句,datetime用的默认值是’0000-00-00 00:00:00’。感觉没啥问题啊,于是查了下,发觉mysql官网给了这么一段话:

The DATE type is used for values with a date part but no time part. MySQL retrieves and displays DATE values in ‘YYYY-MM-DD’ format. The supported range is ‘1000-01-01’ to ‘9999-12-31’.

The DATETIME type is used for values that contain both date and time parts. MySQL retrieves and displays DATETIME values in ‘YYYY-MM-DD hh:mm:ss’ format. The supported range is ‘1000-01-01 00:00:00’ to ‘9999-12-31 23:59:59’.

The TIMESTAMP data type is used for values that contain both date and time parts. TIMESTAMP has a range of ‘1970-01-01 00:00:01’ UTC to ‘2038-01-19 03:14:07’ UTC.

datetime的默认值的起始时间设了限制,改为了’1000-01-01 00:00:00’(我也是醉了)。修改后再导入就OK了。