mysql 常用指令和一般问题

Pycharm连接mysql报错问题

java.lang.RuntimeException: com.mysql.cj.exceptions.InvalidConnectionAttributeException: The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTimezone configuration property) to use a more specifc time zone value if you want to utilize time zone support.
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:61)
at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:85)

我的url为 jdbc:mysql://localhost:3306/test

url后添加:?useUnicode=true&characterEncoding=UTF-8&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC

jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=UTF-8&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC

创建数据库指定编码格式- 模糊搜索 、忽略大小写

CREATE DATABASE test2 DEFAULT CHARACTER SET utf8 COLLATE utf8mb4_unicode_ci; # utf8mb4_unicode_ci 是基于万国码, 对字段的查询不区分大小写

sql = f"""select num_code from report_hcp where part='{part}' and prefix_code='{prefix_code}' and num_code like '%{num_code}%' collate utf8mb4_unicode_ci group by num_code"""
posted @ 2020-09-07 10:19  Tank-Li  阅读(223)  评论(0)    收藏  举报