python3-连接MySQL(mysql.connector与MySQLdb区别)

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python3-连接MySQL(mysql.connector与MySQLdb区别)相关的知识,希望对你有一定的参考价值。

import mysql.connector
cnx = mysql.connector.connect(user=scott, password=tiger,host=127.0.0.1,database=employees)
cnx.close()
import MySQLdb

db = MySQLdb.connect(host="localhost", # your host, usually localhost
                     user="john", # your username
                      passwd="megajonhy", # your password
                      db="jonhydb") # name of the data base

cur = db.cursor() 
cur.execute("SELECT * FROM YOUR_TABLE_NAME")
MySQLdb is a C module that links against the MySQL protocol implementation in the libmysqlclient library. It is faster, but requires the library in order to work.

mysql-connector is a Python module that reimplements the MySQL protocol in Python. It is slower, but does not require the C library and so is more portable.

注:以上内容转自“http://stackoverflow.com/questions/32575857/the-differences-between-mysqldb-and-mysqlconnector”

以上是关于python3-连接MySQL(mysql.connector与MySQLdb区别)的主要内容,如果未能解决你的问题,请参考以下文章

php多数据库问题

lua 文件查询mysql数据库应该怎样写

亚马逊EC2 ubuntu下安装mysql远程无法连接问题o

MySQl数据库的使用

函数para limpiar campos y evitar inyecciones mysql con mysqlu realu escapeu string()

Python3连接MySQL