mysql和mongodb设置外网ip地址能够访问(而不是仅仅localhost)

mysql本地的连接配置文件编写通常是

conn=pymysql.connect(host='localhost',port=3306,user='root',password='123456',db='first_flask',charset='utf8')
cursor=conn.cursor()
cursor.execute('set names utf8')
cursor.execute('set autocommit='1')

如果让localhost变为某一ip地址,则需要

CREATE USER root@'%' IDENTIFIED BY '123456';
GRANT ALL ON *.* TO 'root'@'%';

mysql和mongodb设置外网ip地址能够访问(而不是仅仅localhost)_第1张图片
如图即为设置成功

mongoDB则需要修改配置文件

dbpath=/home/user/mongodb/data
logpath=/home/user/mongodb/logs/mongo.log
logappend=true
journal=true
quiet=true
port=27017
bind_ip=0.0.0.0

其中bind_ip=0.0.0.0表示所有地址均可。(这样的设置可能不安全)

你可能感兴趣的:(mysql和mongodb设置外网ip地址能够访问(而不是仅仅localhost))