簡體   English   中英

使用Tornado(OSX Lion; python 2.7.1)連接MySQL數據庫時遇到問題

[英]Having problems connecting to MySQL database with Tornado (OSX Lion; python 2.7.1)

我的計算機上同時安裝了Tornado和XAMPP。 傳統上,我將PhpMyAdmin用於所有MySQL工作。 但是,我也想與Tornado一起工作。 當我嘗試通過Tornado連接到MySQL時,出現以下錯誤:

Traceback (most recent call last):
  File "__server.py", line 20, in <module>
    class Application(tornado.web.Application):
  File "__server.py", line 40, in Application
    password=options.mysql_password
  File "/Library/Python/2.7/site-packages/tornado-2.4.1-py2.7.egg/tornado/database.py",     line 59, in __init__
    args = dict(conv=CONVERSIONS, use_unicode=True, charset="utf8",
NameError: global name 'CONVERSIONS' is not defined

此錯誤使我相信Tornado認為我的計算機上未安裝MySQL。

這是__server.py相關的Tornado代碼,如果有什么不同的話:

import tornado.database
import tornado.options
import unicodedata
from tornado.options import define, options

define("port", default=8888, help="run on the given port", type=int)
define("mysql_host", default="localhost", help="database host") #127.0.0.1:3306 – this was the      default (should I change it? I didn't get this far in the setup process to know)
define("mysql_database", default="Godzillian1", help="database name")
define("mysql_user", default="root", help="database user")
define("mysql_password", default="", help="database password")

class Application(tornado.web.Application):
    self.db = tornado.database.Connection(
        host=options.mysql_host, 
        database=options.mysql_database,
        user=options.mysql_user, 
        password=options.mysql_password
    )

因此,我的問題是:我是否需要更改龍卷風配置文件中的某些內容或為此進行更改? 當前,所有MySQL文件都位於我的XAMPP文件夾中。 這對我來說似乎很麻煩,但是在我搬走一切之前,我想先檢查一下。 或者,我是否需要完全“重新下載” MySql? 還是龍卷風__server.py本身就是問題。 (注意:為此,我刪除了密碼,並設置了username=root ,以尋求解決方案。)

編輯:我已經成功安裝了MySQL5(64bit)和MySQL-Python,但是我仍然遇到相同的NameError: global name 'CONVERSATIONS' is not defined錯誤NameError: global name 'CONVERSATIONS' is not defined 我應該安裝MySQL的32位版本以便與MySQL-Python兼容嗎? (我以為Lion需要64位MySQL ...但是現在我顯然一無所知)。 這很困惑!

思想大加贊賞。

我想出了解決這個問題的方法。 必須正確地 (重新)安裝MySQL-Python。 我還必須將python 2.7.1切換到32位版本,而不是64位,並且在OSX Lion上 ,必須將MySQL安裝為64位。 似乎很難輕松實現兼容性,因此許多人用來安裝MySQL和MySQL-Python的另一個可行選擇是安裝/使用MacPorts ,然后使用以下兩個命令:

sudo port install py26-mysql 
sudo port install mysql5-server

無論如何,如果這還不夠,請參見此SO問題,以獲取對該解決方案的更全面的說明: 如何在Mac OS X上安裝MySQLdb(MySQL的Python數據訪問庫)?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM