zoukankan      html  css  js  c++  java
  • pycharm mysql8.0 the server time zone value异常解决办法记录

    1:定位到MySQL Server 8.0的设置目录下:C:ProgramDataMySQLMySQL Server 8.0,打开my.ini文件,在[mysqld]节点下,加入default-time-zone='+8:00'默认时区设置,如下截图:

    2.右击我的电脑,选择<计算机管理>,选择<服务和应用程序>下面的<服务>,查找到"mysql80"服务,点击右键,选择重新启动;

    3.pycharm 测试连接成功

    4.测试代码

     1 import pymysql
     2 
     3 # host='127.0.0.1' charset 最好附加上
     4 # db = pymysql.connect(host='localhost', port=3306, user='root', passwd='123456', db='hello', charset='utf8')
     5 db = pymysql.connect('localhost', 'root', '123456', 'yiibaidb')
     6 
     7 # 创建游标对象
     8 cursor = db.cursor()
     9 
    10 try:
    11     # 使用 execute() 方法执行 SQL 查询
    12     cursor.execute('SELECT VERSION()')
    13     # 使用 fetchone() 方法获取单条数据
    14     data = cursor.fetchone()
    15     print('Database version: ', data)
    16     cursor.execute('show databases;')
    17     data = cursor.fetchall()
    18     print('All database: ', data)
    19     cursor.execute('use yiibaidb;')
    20     cursor.execute('show tables;')
    21     data = cursor.fetchall()
    22     print('all yiibaidb tables: ', data)
    23 except Exception as e:
    24     print(e)
    25     db.rollback()
    26 
    27 db.close()

    输出结果如下:

  • 相关阅读:
    异常方法测试实验
    exception测试实验(研究finally的作用)
    idea中文注释出现乱码,我靠自己解决了
    按装parallels tool的失败之路
    实验七
    实验六
    实验五
    实验四
    实验3
    html转义字符图
  • 原文地址:https://www.cnblogs.com/shi-win-snoopy/p/13149448.html
Copyright © 2011-2022 走看看