我在Ubuntu 16.04.5机器上使用SQLalchemy编写了一个Python2.7的程序,其中PHP7.2.15-1+ubuntu16.04.1+deb.sury.org+1、mysql server版本5.7.25。
这个程序似乎运行得很好——我能够查询、比较和存储数据库数据。而且操作很快!我很高兴,直到我意识到大量中止的连接中止了的\u客户端和中止的\u连接。
所有与数据库的连接都是从同一台计算机上完成的。我没有从外部IP连接到数据库。
因此,我怀疑我可能忘记用我的长代码关闭一些会话,我开始解构我的程序并测试它。当我移除零件时,错误继续,直到我达到接近绝对最小值为止。现在,这是正在运行的整个程序,并产生中止的连接和中止的\u客户端。
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from sqlalchemy.pool import NullPool
from sqlalchemy import (Table, Column, Integer, String, DateTime, ForeignKey, schema, func)
from sqlalchemy.ext.declarative import declarative_base
from datetime import date, timedelta, datetime
from sqlalchemy.orm import relationship, backref
engine = create_engine('mysql+pymysql://landingpages-username:password/Database?unix_socket=/var/run/mysqld/mysqld.sock', pool_recycle=3600, echo=False)
conn = engine.connect()
Base = declarative_base()
Session = sessionmaker(bind=engine)
class LandingPagesSimplifi(Base):
__tablename__ = 'landingpages_simplifi'
id = Column(Integer, primary_key=True)
client_id = Column(Integer(), ForeignKey('landingpages_clients.id'))
client_id_simple = Column(String(128), nullable=True)
campaign_id = Column(Integer, nullable=True)
campaign_name = Column(String(256), nullable=True)
ad_id = Column(Integer, nullable=True)
ad_url = Column(String(512), nullable=True)
ad_url_utm = Column(String(512), nullable=True)
created_on = Column(DateTime(),default=datetime.now)
class LandingPagesClients(Base):
__tablename__ = 'landingpages_clients'
id = Column(Integer(), primary_key=True)
name = Column(String(256))
id_google = Column(String(14), nullable=True)
id_facebook = Column(String(64), nullable=True)
id_simplifi = Column(Integer(), nullable=True)
user = Column(Integer(), ForeignKey('landingpages_users.id'))
class LandingPagesUsers(Base):
__tablename__ = 'landingpages_users'
id = Column(Integer(), primary_key=True)
name = Column(String(128))
email = Column(String(256))
session = Session()
first_record = session.query(LandingPagesSimplifi).first()
print first_record.id;
session.close()
不奇怪,返回“1”。 没有错误。
但是如果我运行sudo tail/var/log/mysql/错误.log紧接着,我将看到:
[Note] Aborted connection 212 to db: 'LandingPages' user: 'username' host: 'localhost' (Got an error reading communication packets)
在到达Stackoverflow之前,我尽最大努力解决问题,我尝试了以下操作,在每种情况下,运行程序后仍然会立即出现错误。
首先我试着换主机和引擎插座,从。。。
^{pr2}$至
^{pr3}$它产生的答案是“1”,但会产生相同的错误。
或
^{pr4}$它也会产生“1”,但会产生此错误。 以下附加操作将产生“1”,但仍会导致此错误。
如果我删除池的回收位。
更改create_u引擎,使其连接到此服务器上的其他数据库。
使用不同的授权凭据连接到数据库。
将绑定地址更改为我的计算机的外部IP,将其更改为127.0.0.1,更改为0.0.0.0,并将此行注释为完全。
唯一有帮助的是如果我包括sqlalchemy.pool将NullPool导入到我的程序,并将poolclass=null池添加到create\engine参数。 但我真的想用个游泳池,如果我能的话,对吧?
不过,这可能会给人一个线索,说明问题在哪里。然而,我自己研究却找不到任何帮助。我不能问正确的问题。 有人对问题可能在哪里有任何建议吗?
另一个重要信息:同一sql server承载着另外两个数据库,这些数据库由该计算机本地访问(通过LarvelPHP web应用程序)访问,0个中止的连接或中止的客户端来自该程序。
其他重要信息:
show global variables like '%timeout%';
+-----------------------------+----------+
| Variable_name | Value |
+-----------------------------+----------+
| connect_timeout | 10 |
| delayed_insert_timeout | 300 |
| have_statement_timeout | YES |
| innodb_flush_log_at_timeout | 1 |
| innodb_lock_wait_timeout | 50 |
| innodb_rollback_on_timeout | OFF |
| interactive_timeout | 28800 |
| lock_wait_timeout | 31536000 |
| net_read_timeout | 30 |
| net_write_timeout | 60 |
| rpl_stop_slave_timeout | 31536000 |
| slave_net_timeout | 60 |
| wait_timeout | 28800 |
+-----------------------------+----------+
13 rows in set (0.00 sec)
感谢您的帮助。
在ph53i/yadmin/share/usdmin/line中解决了这个问题_interface.lib.php接口在
我变了
到
^{pr2}$保存并重新启动了apache2。 注意:在进行此更改之前,上述问题与无法在phpmyadmin中导入或导出数据库相吻合(给我一个错误500)。 通过对此文件进行此更改,两个问题都得到了解决。在
相关问题 更多 >
编程相关推荐