1. 运行 tornado-serv.py时报错: python tornado_serv.py Traceback (most recent call last): File "tornado_serv.py", line 6, in <module> import torndb ImportError: No module named torndb
解决: 需要安装 torndb # pip install torndb
2. 运行 tornado-serv.py时报错: Traceback (most recent call last): File "tornado_serv.py", line 6, in <module> import torndb File "/usr/local/python2.7.3/lib/python2.7/site-packages/torndb.py", line 33, in <module> import MySQLdb.constants ImportError: No module named MySQLdb.constants
解决: 安装MySQL-python-1.2.3 # wget http://sourceforge.net/projects/mysql-python/files/mysql-python/1.2.3/MySQL-python-1.2.3.tar.gz/download # tar zxf MySQL-python-1.2.3.tar.gz && cd MySQL-python-1.2.3 # python setup.py build # python setup.py install
3. 运行 python tornado_serv.py 时报错: Traceback (most recent call last): File "tornado_serv.py", line 6, in <module> import torndb File "/usr/local/python2.7.3/lib/python2.7/site-packages/torndb.py", line 33, in <module> import MySQLdb.constants File "build/bdist.linux-x86_64/egg/MySQLdb/__init__.py", line 19, in <module> File "build/bdist.linux-x86_64/egg/_mysql.py", line 7, in <module> File "build/bdist.linux-x86_64/egg/_mysql.py", line 6, in __bootstrap__ ImportError: libmysqlclient_r.so.15: cannot open shared object file: No such file or directory
4. python tornado_serv.py ERROR:root:Cannot connect to MySQL on localhost Traceback (most recent call last): File "/usr/local/python2.7.3/lib/python2.7/site-packages/torndb.py", line 96, in __init__ self.reconnect() File "/usr/local/python2.7.3/lib/python2.7/site-packages/torndb.py", line 113, in reconnect self._db = MySQLdb.connect(**self._db_args) File "build/bdist.linux-x86_64/egg/MySQLdb/__init__.py", line 81, in Connect return Connection(*args, **kwargs) File "build/bdist.linux-x86_64/egg/MySQLdb/connections.py", line 187, in __init__ super(Connection, self).__init__(*args, **kwargs2) OperationalError: (1045, "Access denied for user ‘root‘@‘localhost‘ (using password: YES)")
数据库中显示如下: mysql> select * from chatting; +------+--------------------------+ | id | content | +------+--------------------------+ | 1 | hello | | 1 | who | | 1 | this is | | 1 | what are you doing | | 1 | fet | | 1 | this is my first version | +------+--------------------------+ 6 rows in set (0.00 sec)