关于MySQL中pymysql安装的问题。

一 一般情况下我们直接在终端输入:

pip3 install pymysql

就能够自动安装成功。

但是有时候我们必须先指定一个python解释器:

比如我们指定python3
在终端cmd输入:python3  -m pip install pymysql
就行了。。。。。。。。。。。

 等安装成功之后,我们就可以在pycahrm中直接import pymysql导入啦:

import pymysql #pip3 install pymysql

conn=pymysql.connect(
    host='127.0.0.1',
    port=3306,
    user='root',
    password='123',
    database='db42',
    charset='utf8'
)
cursor=conn.cursor(pymysql.cursors.DictCursor)

# rows=cursor.execute('show tables;')
rows=cursor.execute('select * from class;')
print(rows)


# print(cursor.fetchone())
# print(cursor.fetchone())
# print(cursor.fetchmany(2))
# print(cursor.fetchall())
# print(cursor.fetchall())


# print(cursor.fetchall())
# cursor.scroll(3,'absolute')
# print(cursor.fetchone())

print(cursor.fetchone())
print(cursor.fetchone())
cursor.scroll(1,'relative')
print(cursor.fetchone())

cursor.close()
conn.close()
 
 
 
 
 
 

  

猜你喜欢

转载自www.cnblogs.com/zhangsanfeng/p/9027026.html