pycharm连数据库:Connection to @localhost failed. [08001] Could not create connection to database server.

报错形式

点Test Connection连接时报错代码:
Connection to @localhost failed.
[08001] Could not create connection to database server. Attempted reconnect 3 times. Giving up.
pycharm连数据库:Connection to @localhost failed. [08001] Could not create connection to database server.

解决方法

url后面增加?serverTimezone=Asia/Shanghai&characterEncoding=utf8即可解决>
如图所示:pycharm连数据库:Connection to @localhost failed. [08001] Could not create connection to database server.

上述参数解释:

1、在url后面加:?serverTimezone=utc
UTC代表的是全球标准时间 ,但是我们使用的时间是北京时区也就是东八区,领先UTC八个小时。UTC + (+0800) = 本地(北京)时间

2、使用中国标准时间。也是就serverTimezone=Asia/Shanghai

3、中文乱码的解决方案:characterEncoding=utf8

4、如还报错:请选择Driver > MySQL For 5.1
然后再进行连接
pycharm连数据库:Connection to @localhost failed. [08001] Could not create connection to database server.
点击 OK,即连接成功。
pycharm连数据库:Connection to @localhost failed. [08001] Could not create connection to database server.