zoukankan      html  css  js  c++  java
  • MySQL解决方案

    目录

    Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj....

    总体概括就是两个异常:

    1. Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.

    原因:加载类'com.mysql.jdbc.Driver' 已经过时了。新的驱动类是“com.mysql.cj.jdbc.Driver”。驱动程序通过SPI自动注册,而手动加载类通常是不必要的。、

    解决方法:1. 使用8.0.13版本的驱动 2.将驱动 com.mysql.jdbc.Driver  改为  com.mysql.cj.jdbc.Driver

    jdbc.driver=com.mysql.cj.jdbc.Driver

    2. 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. 

    原因:服务器时区值“????±××?±?无法识别或代表一个以上的时区。如果希望利用时区支持,则必须配置服务器或JDBC驱动程序(通过serverTimezone配置属性)以使用更具体的时区值。

    解决方案:jdbc.url 加上   characterEcoding=utf-8&useSSL=false&serverTimezone=UTC&rewriteBatchedStatements=true

    jdbc:mysql://127.0.0.1:3306/xxx?useSSL=false&useUnicode=true&characterEncoding=UTF-8&serverTimezone=GMT%2B8
    

    项目启动报错The server time zone value '�й���׼ʱ��' is unrecognize

    报错The server time zone value '�й���׼ʱ��' is unrecognized or represents more than one time zone. You must...

        原因是使用了Mysql Connector/J 6.x以上的版本,然后就报了时区的错误,解决方法:

        在配置url的时候不能简单写成 :

        jdbc:mysql://localhost:3306/yzu?serverTimezone=UTC

        而是要写成 :

        jdbc:mysql://localhost:3306/yzu?serverTimezone=UTC
    

      

    Python之MySQLdb

    MySQLdb是用于Python链接Mysql数据库的接口,它实现了Python数据库API规范V2.0,基于MySql C API上建立的。

      1. MySQLdb安装

        (1)安装Mysql,参考上篇博客数据库之MySql

        (2)使用pip安装MySQLdb:pip install MySQL-python

            但是安装的时候会报错:error: command 'C:\Program Files\Microsoft Visual Studio 14.0\VC\BIN\cl.exe' failed with exit status 2

            下面推荐两种方法进行解决:

             a. 下载Python-3.5及上版本扩展的mysql驱动:https://pypi.python.org/pypi/mysqlclient/1.3.10

                 之后将下载后的*.whl文件跟pip.exe放在同个目录(一般是在 ..Python36Scripts 里)

            然后用cmd命令进入到这个目录执行PIP命令安装:pip install mysqlclient-1.3.10-cp36-cp36m-win32.whl 

           b. 安装pymysql代替:pip install pymysql 

    注:以上安装方法内容来自原文https://www.cnblogs.com/bu1tcat/p/8283742.html     

      2. MySQLdb实例

    复制代码
    #coding=utf-8
    
    import sys
    import MySQLdb as db
    import csv
    
    def parse_csv(csvfile):
        with open(csvfile, 'r') as pf:
            reader = csv.reader(pf, delimiter=',')
            header = next(reader)
            csvdata = []
            for row in reader:
                csvdata.append(row)
        return header, csvdata        
            
        
    #链接数据库
    def mysqldb_operator(data):
        conn = db.connect(host="localhost", user="root", passwd="", db="xbqr", charset="utf8")
        print (conn)
        print ("datebase connect success!")
        curs = conn.cursor()
        #创建表之前先删除表
        curs.execute("drop table IF EXISTS table_xbqr")
        conn.commit()
        #创建表
        query = "create table table_xbqr(
            SupplierName VARCHAR(32),
            InvoiceNumber VARCHAR(32),
            PartNumber VARCHAR(32),
            Cost VARCHAR(32),
            PurchaseDate DATE)"
        curs.execute(query)
        conn.commit()
        for row in data:
            curs.execute("INSERT INTO table_xbqr VALUES(%s,%s,%s,%s,%s);", row)
            conn.commit()
        curs.execute("select * from table_xbqr")
        conn.commit()
        selectdata = curs.fetchall()
        print (selectdata)
    
    if __name__ == "__main__":
        csvfile = sys.argv[1]
        print ("csv file name:", csvfile)
        header, data = parse_csv(csvfile)
        print ("header:")
        print (header)
        print ("csvdata:")
        print (data)
        mysqldb_operator(data)
    复制代码

  • 相关阅读:
    Java安全之JNDI注入
    Visual Studio 2019 升级16.8之后(升级.Net 5),RazorTagHelper任务意外失败
    .Net Core 3.1升级 .Net 5后出现代码错误 rzc generate exited with code 1.
    重走py 之路 ——普通操作与函数(三)
    重走py 之路 ——字典和集合(二)
    设计模式结(完结篇)
    重走py 之路 ——列表(一)
    RestfulApi 学习笔记——分页和排序(五)
    RestfulApi 学习笔记——查询与过滤还有搜索(五)
    Android开发 Error:The number of method references in a .dex file cannot exceed 64K.Android开发 Error:The number of method references in a .dex file cannot exceed 64K
  • 原文地址:https://www.cnblogs.com/Dreamer-Jie/p/14132399.html
Copyright © 2011-2022 走看看