在Ubuntu上运行时,python脚本会抛出mysql错误,但在OSX

时间:2016-07-28 20:15:55

标签: mysql python-2.7 ubuntu mysql-python mysql-error-1064

我有一个python脚本,通过mysqldb连接器处理MySQL。同样的脚本在我的OSX机器上运行得非常好,同时在Ubuntu机器上运行时会破坏抛出MySql错误异常。

以下两个系统的详细信息:

OSX -

  

python --version => Python 2.7.11(通过Homebrew安装)
  哪个python => / usr / local / bin / python
  mysql --version => mysql Ver 14.14 Distrib 5.7.10,for osx10.9(x86_64)using EditLine wrapper

Ubuntu -

  

python --version => Python 2.7.6(默认系统Python)
  哪个python => / usr / bin / python
  mysql --version => mysql Ver 14.14 Distrib 5.5.50,debian-linux-gnu(x86_64)使用readline 6.3

在Ubuntu框上运行脚本时收到的错误是:

Traceback (most recent call last):
  File "my_program.py", line 364, in <module>
    dao = DataAccessObject(debugger)
  File "/home/path_to_file/project/handle_storage.py", line 42, in __init__
    self.cur.execute(create_restaurant_table)
  File "/usr/local/lib/python2.7/dist-packages/MySQLdb/cursors.py", line 205, in execute
    self.errorhandler(self, exc, value)
  File "/usr/local/lib/python2.7/dist-packages/MySQLdb/connections.py", line 36, in defaulterrorhandler
    raise errorclass, errorvalue
_mysql_exceptions.ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(6) NOT NULL, some_time_column DATETIME NOT NULL, record_hash TEXT NOT NULL, PRIMARY K' at line 1")

请帮助我理解这里出了什么问题?如果我的代码确实存在问题,正如上面的错误消息所示,为什么在OSX机器上脚本运行良好?

根据上述例外,查询中断的行是:

CREATE TABLE IF NOT EXISTS my_table (id int NOT NULL AUTO_INCREMENT, name TEXT, area TEXT, address TEXT, locality TEXT, fee_type TEXT, charge TEXT, cost TEXT, stuff TEXT, rating TEXT, later TEXT, type TEXT, cityCharge TEXT, record_entry_at DATETIME(6) NOT NULL, as_on DATETIME NOT NULL, record_hash TEXT NOT NULL, PRIMARY KEY (id));

1 个答案:

答案 0 :(得分:1)

对DATETIME数据类型的官方文档进行的一些快速研究表明,在5.6.4之前不会引入小数秒指定符。

  

MySQL 5.6.4及更高版本扩展了小数秒支持......

这是我遵循的文档路径:

  1. http://dev.mysql.com/doc/refman/5.7/en/datetime.html
  2. http://dev.mysql.com/doc/refman/5.7/en/fractional-seconds.html
  3. http://dev.mysql.com/doc/refman/5.6/en/fractional-seconds.html(手动更改网址&#34; 5.7&#34;到&#34; 5.6&#34;到达此网址。)
相关问题