3

我在 Django 中编写了一个服务器应用程序,并使用 Tastypie 为移动应用程序提供 API,并使用本地 MySQL 服务器为数据库提供服务。

似乎查询被缓存,直到进程被终止或结束。如果我在后端创建一个新用户,如果我重新启动 uWSGI 或 MySQL,或者如果我从不同的浏览器登录到后端,它将首先出现在列表中。

Mysql进程列表

41  example localhost:58747   example        13  Sleep                                                                                                                     
42  example localhost:58748   example        16  Sleep

此外,如果我终止睡眠的进程,它也会触发数据的刷新。

uWSGI 配置

[uwsgi]
vhost = true
plugins = python
socket = /tmp/example.com.sock
master = true
enable-threads = true
processes = 2
wsgi-file = /var/sites/example-server/example/example/wsgi.py
virtualenv = /var/sites/example-server/PYTHON_ENV
chdir = /var/sites/example-server/example
touch-reload = /var/sites/example-server/example/reload

nginx 配置

server {
    client_max_body_size 20M;
    listen  80;
    server_name example.com;
    access_log /var/log/nginx/example.com_access.log;
    error_log /var/log/nginx/example.com_error.log;

    location / {
        uwsgi_pass  unix:///tmp/example.com.sock;
        include     uwsgi_params;
    }

    location /media/  {
        alias /var/sites/example-server/example/example/media/;
    }

    location  /static/ {
        alias  /var/sites/example-server/example/example/static/;
    }
}

我的.cnf

[client]
port            = 3306
socket          = /var/run/mysqld/mysqld.sock

[mysqld_safe]
socket          = /var/run/mysqld/mysqld.sock
nice            = 0

[mysqld]
user            = mysql
pid-file        = /var/run/mysqld/mysqld.pid
socket          = /var/run/mysqld/mysqld.sock
port            = 3306
basedir         = /usr
datadir         = /var/lib/mysql
tmpdir          = /tmp
lc-messages-dir = /usr/share/mysql
skip-external-locking
bind-address            = 127.0.0.1
key_buffer              = 16M
max_allowed_packet      = 16M
thread_stack            = 192K
thread_cache_size       = 8
myisam-recover         = BACKUP
query_cache_limit       = 1M
query_cache_size        = 16M
log_error = /var/log/mysql/error.log
expire_logs_days        = 10
max_binlog_size         = 100M
mysqldump]
quick
quote-names
max_allowed_packet      = 16M

[mysql]

[isamchk]
key_buffer              = 16M

transaction-isolation = READ-COMMITTED
!includedir /etc/mysql/conf.d/

我该怎么做才能让这个问题消失?

干杯莫顿

4

1 回答 1

1

我有同样的行为,发现这篇文章https://plus.google.com/u/0/101898908470597791359/posts/AuMJdgEo93k

在 Django 上的 settings.py(仅 OPTIONS 键)上添加这一行:

DATABASES = {
   'default': {    
       'OPTIONS': { "init_command": "SET storage_engine=INNODB, SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED", }
    }
}

似乎已经解决了这个问题。

于 2013-12-04T17:40:14.713 回答