Created
April 21, 2017 17:33
-
-
Save rbk/ba0dceb5fe9b20a18584d12fe734df1f to your computer and use it in GitHub Desktop.
Python 3.5 Database interaction sample
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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