繁体   English   中英

web.py连接到mysql错误

[英]web.py connect to mysql error

当我使用web.py连接本地mysql时,显示一些错误:

Traceback (most recent call last):
  File "code.py", line 7, in <module>
    db = web.database(dbn='mysql',user='root',pw='123456',db='pytable')
  File "/Library/Python/2.6/site-packages/web.py-0.34-py2.6.egg/web/db.py", line 1078, in database
    return _databases[dbn](**params)
  File "/Library/Python/2.6/site-packages/web.py-0.34-py2.6.egg/web/db.py", line 928, in __init__
    import MySQLdb as db
  File "build/bdist.macosx-10.6-universal/egg/MySQLdb/__init__.py", line 19, in <module>
  File "build/bdist.macosx-10.6-universal/egg/_mysql.py", line 7, in <module>
  File "build/bdist.macosx-10.6-universal/egg/_mysql.py", line 6, in __bootstrap__
ImportError: dlopen(/Users/rlog/.python-eggs/MySQL_python-1.2.3-py2.6-macosx-10.6-universal.egg-tmp/_mysql.so, 2): no suitable image found.  Did find:
    /Users/rlog/.python-eggs/MySQL_python-1.2.3-py2.6-macosx-10.6-universal.egg-tmp/_mysql.so: mach-o, but wrong architecture

我的python代码是这样的:

import web
render = web.template.render('templates/')
urls = (
    "/(.*)","index"
)
app = web.application(urls,globals())
db = web.database(dbn='mysql',user='root',pw='123456',db='pytable')
class index:
    def GET(self):
        todos = db.select('todo')
        return render.index(todos)
if __name__=="__main__":app.run()

我的python版本是2.6.1

我该如何解决?

谢谢

db = web.database(dbn ='mysql',db ='projefg9_emearmy_ps_erc',user ='root',pw ='admin')

dbn-您正在使用的数据库(对于mysql,它是“ mysql”)db-数据库名称用户-数据库的用户名pw-数据库的密码

您为Python安装的mysql适配器已损坏或用于其他体系结构。 我不确定您如何安装它(或这些东西在OSX上如何工作)。 这是一个讨论安装的问题 如果您做对了,它应该可以正常工作(假设凭据正确)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM