0 安装模块,pip install pymysql

1 pymql的作用是在python程序中操作mysql,同样是一个客户端,需要链接服务端后进行数据操作

 1 import pymysql
 2 #链接需要指定所链接的ip地址和端口号,本地客户端可以直接写localhost,
 3 #建立链接需要指定字符集编码,此时为utf8,不是utf-8
 4 conn=pymysql.connect(host='localhost',
 5                      port=3306,
 6                      user='root',
 7                      password='407509',
 8                      #database='test',
 9                      charset='utf8')
10 cursor = conn.cursor()
11 
12 sql = 'show databases;'
13 res = cursor.execute(sql)
14 print(cursor.fetchall())
链接数据库,查看库

相关文章:

  • 2021-09-30
  • 2021-05-31
  • 2022-12-23
  • 2021-06-05
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-09-11
  • 2022-12-23
  • 2021-07-19
  • 2021-05-25
  • 2022-12-23
相关资源
相似解决方案