2016-05-17 76 views
0

我是Python新手,使用Enthought Canopy Express进行学习。作为一部分,我正在寻找一个将Canopy连接到mysql的选项。我没有找到任何材料。如果你知道我可以在Canopy Express中使用mysql的任何方法,请分享。将Canopy连接到mysql

我使用的是Mac OS X版本10.9

雨棚路径是: /Users/mz/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages

MySQL是5.6版本具有以下路径: MySQL的是/ usr /本地/ MySQL的/斌/ MySQL的

回答

0

可以使用冠层包管理器安装pymysqlenter image description here

一旦安装,根据Python的PEP249 DB API访问pymysql(创建连接时,得到的光标等):

In [1]: import pymysql 

In [2]: connection = pymysql.connect? 
Signature: pymysql.connect(*args, **kwargs) 
Docstring: 
     Establish a connection to the MySQL database. Accepts several 
     arguments: 

     host: Host where the database server is located 
     user: Username to log in as 
     password: Password to use. 
     database: Database to use, None to not use a particular one. 
     port: MySQL port to use, default is usually OK. 
... 
+0

喜添,后我连接使用命令到MySQL的:进口pymysql 连接= pymysql.connect (host ='localhost',database ='ali',user ='root',password =''),我如何测试我连接到mysql – Mary

+0

下一步将创建一个游标然后使用它执行一条SQL语句:'cursor = connection.cursor(); cursor.execute(“SELECT * FROM my_table”); cursor.fetchall()' –