远程数据库连接
2022年8月4日...大约 2 分钟
远程数据库连接
远程数据库连接首先关闭防火墙
monogo开启远程访问
mongo关闭服务
mysql开启远程连接 ......
远程数据库连接首先关闭防火墙
#一、下面是red hat/CentOs7关闭防火墙的命令!
#查看防火状态
systemctl status firewalld
service iptables status
#暂时关闭防火墙
systemctl stop firewalld
service iptables stop
#永久关闭防火墙
systemctl disable firewalld
chkconfig iptables off
#重启防火墙
systemctl enable firewalld
service iptables restart
#永久关闭后重启
//暂时还没有试过
chkconfig iptables on
#二、firewalld
#Centos7默认安装了firewalld,如果没有安装的话,可以使用 yum install firewalld firewalld-config进行安装。
#启动防火墙
systemctl start firewalld
#禁用防火墙
systemctl stop firewalld
#设置开机启动
systemctl enable firewalld
#停止并禁用开机启动
sytemctl disable firewalld
#重启防火墙
firewall-cmd --reload
#查看状态
systemctl status firewalld或者 firewall-cmd --state
#查看版本
firewall-cmd --version
monogo开启远程访问
dbpath=/usr/local/mongodb/mongodb-3.6.5/data/db #数据文件存放目录
logpath=/usr/local/mongodb/mongodb-3.6.5/data/log/mongodb.log #日志文件存放目录
port=27017 #端口号
fork=true #以守护程序的方式启用,即在后台运行
logappend = true #日志以追加的形式添加
bind_ip = 0.0.0.0 #可以访问的地址. 127.0.0.1表示自己访问, 0.0.0.0 表示所有人都能访问
mongo关闭服务
#关闭服务 /data/db 代表数据库文件位置
mongod --shutdown --dbpath /data/db
mysql开启远程连接
- mysql操作
mysql -u root -p
#修改mysql密码
mysql> use mysql;
mysql> update user set password = Password('root') where User = 'root';
mysql> flush privileges;
- 设置远程连接
#第一步登录mysql
mysql -u root -p
#第二步切换数据库
mysql> use mysql;
#使用 mysql 命令为 root 用户授权 mysql 远程连接服务
#第三步:
grant all privileges on *.* to 'root'@'%' identified by 'root' with grant option;
#说明:此命令是为密码为 root 、IP(%)任意的 root 用户授权。(%:模糊查询,所有 IP 都可以,,可指定其他主机 IP;BY 后的 'root' 为密码)
#第四步:
flush privileges;
#将配置写入 mysql 授权表中
Powered by Waline v3.3.2