python 是目前比较流行的语言,所以学习一下
首先需要 安装MySQL-python驱动
下载地址:http://dev.mysql.com/downloads/connector/python/
根据自己操作系统和python版本选择相对应的驱动
例如(mysql-connector-python-2.1.3-py2.7-winx64.msi)
接下来演示:如何连接到MySQL服务器的zizai数据库
Python 2.7.12 (v2.7.12:d33e0cf91556, Jun 27 2016, 15:24:40) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import mysql.connector
>>> conn=mysql.connector.connect(
... user='root',
... password='root',
... database='zizai')
>>> cursor=conn.cursor()
>>> cursor.execute('select * from user where 1=1')
>>> values=cursor.fetchall()
>>> values
[(1, u'xxa'), (1, u'xxb'), (1, u'xxx')]
>>> cursor.close()
True
>>> conn.close()
>>>