Skip to content

Instantly share code, notes, and snippets.

@rbk
Created April 21, 2017 17:33
Show Gist options
  • Save rbk/ba0dceb5fe9b20a18584d12fe734df1f to your computer and use it in GitHub Desktop.
Save rbk/ba0dceb5fe9b20a18584d12fe734df1f to your computer and use it in GitHub Desktop.
Python 3.5 Database interaction sample
# note: Must install pymysql: `pip3 install pymysql`
import pymysql
conn= pymysql.connect(host='localhost',user='root',password='password',db='s1',charset='utf8mb4',cursorclass=pymysql.cursors.DictCursor)
a=conn.cursor()
sql='CREATE TABLE `users` (`id` int(11) NOT NULL AUTO_INCREMENT,`email` varchar(255) NOT NULL,`password` varchar(255) NOT NULL,PRIMARY KEY (`id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;'
a.execute(sql)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment