Python3.x : Operation database - pymysql
First, you need to download a module:
pip3 install PyMySQL
Next is the code:
#!/usr/bin/python
# -*- coding: UTF-8 -*-
import pymysql
localhost = "xxxxxxxx" # Your database address
username = "xxxxxxxx" # Your username
password = "xxxxxxxx" # Your password
database = "xxxxxxxx" # Your database instance
db = pymysql.connect(localhost, username, password, database, charset="utf8") # Pay attention to coding
cursor = db.cursor()
cursor.execute("select * from account") # Try to query the sql statement
cursor.nextset()
data = cursor.fetchone()
print(data)
cursor.nextset()
data = cursor.fetchone()
print(data)
data_all = cursor.fetchall() # Get all the data












