Python/pymysql
Appearance
< Python
Examples
- connect
import pymysql db = pymysql.connect(host=localhost, port=3306, user="root", password="1234")
- show version
try:
with db:
cursor = db.cursor()
cursor.execute("SELECT VERSION()")
version = cursor.fetchone()
print("Database version: {}".format(version[0]))
except Exception as e:
print(e)
- create database
try:
with db:
cursor = db.cursor()
cursor.execute("CREATE DATABASE carsearch")
except Exception as e:
print(e)