为啥我得会报错呢?
来源:3-4 python更新mysql数据
			热爱编程学习
2020-09-03
import pymysql
from mysql.mysql.sql import conn
class mysql(object):
def init(self):
self.get_conn()
def get_conn(self):
    try:
       self.conn=pymysql.connect(
            host='hc-dev.ck420txi7os7.ap-southeast-1.rds.amazonaws.com',
            user='admin',
            passwd='******',
            db='guns',
            port=3306,
            charset='utf8'
        )
    except pymysql.Error as e:
        print('Error: %s' % e)
def close_conn(self):
    try:
        if self.conn:
            conn.close()
    except pymysql.Error as e:
        print('Error: %s' % e)
def get_one(self):
   # sql="SELECT * FROM t_user WHERE UUID= %s 'acd31223ae564a528f4cddb413c1e0bf'"
    sql="SELECT * FROM `t_promotion_bonus` WHERE UUID='a1b7a4c59a5e41eba7292094cba4c713'"
    cursor=self.conn.cursor()
    cursor.execute(sql,('test',))
    #print(cursor.rowcount)
    #rest=cursor.fetchone()
    rest=dict(zip([k[0]for k in cursor.description],cursor.fetchone()))
    print(rest)
    #print(rest['title'])
    cursor.close()
    self.close_conn()
    return rest
def add_one(self):
    sql=(
        "INSERT INTO `guns`.`t_market_bonus`(`UUID`, `SOURCE_UUID`, `PRODUCT_ORDER`, `AMOUNT`, `MY_M_LEVEL`, `MY_REFERRER_NUMBER`, `DIVIDEND_RATE`, `WHETHER_CONSOLATION_PRIZE`, `DIVIDEND_BASE`, `HIGHER_INTEREST_RATE`, `CREATETIME`) VALUES"
    "(%s, %s, %s, %s, %s, %s,%s, %s, %s, %s,%s);"
    )
    cursor=self.conn.cursor()
    cursor.execute(sql,('20433510a2b746f2bd073e9df163413b', 'NULL', 'NULL', '0.0291752304', '1', '10', '0.0500000000', '0', '1', '0.0500000000', '1587298331000'))
    self.conn.commit()
    cursor.close()
    self.close_conn()
def main(self):
    obj=mysql()
    #rest=obj.get_one()
    #print(rest['title'])
    obj.add_one()
if __name__=='__main__':
    main()
D:\python3\python.exe "D:/PyCharm Community Edition 2017.1.1/untitled/mysql/mysql/mysql.py"
Traceback (most recent call last):
File “D:/PyCharm Community Edition 2017.1.1/untitled/mysql/mysql/mysql.py”, line 3, in 
from mysql.mysql.sql import conn
File “D:\PyCharm Community Edition 2017.1.1\untitled\mysql\mysql\mysql.py”, line 3, in 
from mysql.mysql.sql import conn
ModuleNotFoundError: No module named ‘mysql.mysql’; ‘mysql’ is not a package
Process finished with exit code 1
写回答
	1回答
- 
				
				
使用mysqlclient试试:
pip install mysqlclient012020-09-05 
Python操作三大主流数据库-MySQL+MongoDB+Redis
				一次实战同时掌握Python操作MySQL,MongoDB,Redis 三大数据库使用技巧
			
			
		2024 学习 · 376 问题
相似问题