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 # 动态追踪修改
本地能连接阿里云数据库吗
root@iZj6c0mehodp5r0c89eyrmZ:~# netstat -tunlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.53:53 0.0.0.0:* LISTEN 403/systemd-resolve
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 520/sshd: /usr/sbin
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 21877/nginx: master
udp 0 0 127.0.0.53:53 0.0.0.0:* 403/systemd-resolve
udp 0 0 172.24.90.125:68 0.0.0.0:* 392/systemd-network
udp 0 0 127.0.0.1:323 0.0.0.0:* 462/chronyd
udp6 0 0 ::1:323 :::* 462/chronyd
您好,您的问题已经有小伙伴解答了,如果有答案帮您提供解决思路,请点击【采纳】按钮,给回答的人一些鼓励哦~~