2016-05-17 59 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()' –