Beginner Python, currently in both e-books and online tutorials, is for python2.7, but there are changes to some of the syntax and modules.
Like what
URLLIB2 is a python-brought module that does not need to be downloaded.
URLLIB2 was changed to Urllib.request in python3.x.
The most common way to connect MySQL in Python 2.x is mysqldb. A lot of tutorials on the Web are also using this module (I've also been unsuccessful with PIP install MySQLdb installation).
Currently MYSQLDB does not support python3.x. You can use MySQL connnecter instead.
import mysql.connectorimport sysuser = ' root ' pwd = ' root ' host = ' 20.0.2.50 ' db= ' mysql ' create_tab_sql = ' create table if not exists tab_test ( tab_name varchar (, ) city_name varchar ()             CHARACTER SET UTF8 "Conn = mysql.connector.connect (USER=USER,PASSWORD=PWD,HOST=HOST,DATABASE=DB) cursor = Conn.cursor () Try: cursor.execute (create_tab_sql) except mysql.connector.error As err: print ("create table ' Tab_test ' failed.") print ("error:{}". Format (ERR.MSG)) sys.exit ()
This article is from the "Libydwei" blog, make sure to keep this source http://libydwei.blog.51cto.com/37541/1774772
Python3 connecting MySQL Database