flask restful接口本地测试都是没问题的,项目部署到阿里云后,执行python main.py runserver也能正常跑去来,但是执行数据库迁移时,命令语句为python main.py command1 migrate,报错Can't connect to MySQL server on '0.0.0.0' ([Errno 111] Connection refused)。
按照网上指导,已经修改/etc/mysql/mysql.conf.d/mysqld.cnf中的bind-address = 127.0.0.1 为bind-address = 0.0.0.0,service mysql restart后还是报这个错。
执行netstat -tunlp没看到又3306的进程。
mysqld.cnf中的配置如下:
```shell
[mysqld]
# * Basic Settings
skip-grant-tables
#
user = mysql
# pid-file = /var/run/mysqld/mysqld.pid
# socket = /var/run/mysqld/mysqld.sock
# port = 3306
# datadir = /var/lib/mysql
# If MySQL is running as a replication slave, this should be
# changed. Ref https://dev.mysql.com/doc/refman/8.0/en/server-system-variables.html#sysvar_tmpdir
# tmpdir = /tmp
#
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
bind-address = 0.0.0.0
#
# * Fine Tuning
#
key_buffer_size = 16M
# max_allowed_packet = 64M
# thread_stack = 256K
# thread_cache_size = -1
# This replaces the startup script and checks MyISAM tables if needed
# the first time they are touched
myisam-recover-options = BACKUP
python关于数据库配置代码如下:
class Config():
ENV = 'production'
DEBUG = True
'''配置数据库'''
SQLALCHEMY_DATABASE_URI = 'mysql+pymysql://root:123456@0.0.0.0:3306/apidb1'
SQLALCHEMY_TRACK_MODIFICATIONS = False # 动态追踪修改