7 Answers
Best Answer
为了安全考虑,OneinStack仅允许云主机本机(localhost)连接数据库,如果需要远程连接数据库,需要如下操作(缺一不可):
1. 云主机安全组端口开放3306端口
参考文档:《云主机安全组端口开放教程》
2. 打开iptables 3306端口
PS: 只有开启了iptables才需要此步骤!
如果您的操作系统为CentOS系列:
iptables -I INPUT 4 -p tcp -m state --state NEW -m tcp --dport 3306 -j ACCEPT service iptables save #保存iptables规则
如下图:
如果您的操作系统为Ubuntu/Debian系列:
iptables -I INPUT 4 -p tcp -m state --state NEW -m tcp --dport 3306 -j ACCEPT iptables-save > /etc/iptables.up.rules #保存iptables规则
如下图:
3. 数据库授权
注意⚠️:远程连接新建一个帐号(帐号名不能为root)。
如:添加一个用户名为db_user,密码为db_pass,授权为% (%表示所有IP能连接)对db_name数据库所有权限,命令如下:
1)MySQL8.0版本
# mysql -uroot -p
MySQL [(none)]> create user db_user@'%' identified by 'db_pass'; #创建用户
MySQL [(none)]> grant all privileges on db_name.* to db_user@'%' with grant option; #授权
MySQL [(none)]> exit; #退出数据库控制台,特别注意有分号
2)其余MySQL版本
# mysql -uroot -p
MySQL [(none)]> grant all privileges on db_name.* to db_user@'%' identified by 'db_pass'; #授权语句,特别注意有分号
MySQL [(none)]> flush privileges;
MySQL [(none)]> exit; #退出数据库控制台,特别注意有分号
如下图:
Percona安装以后无法登录phpmyadmin
重启后也报错
ERROR! MySQL (Percona Server) PID file could not be found!
Starting MySQL (Percona Server).170308 18:46:54 mysqld_safe The file /usr/local/Percona-Server-5.6.35-rel80.0-Linux.x86_64.ssl101/bin/mysqld
does not exist or is not executable. Please cd to the mysql installation
directory and restart this script from there as follows:
./bin/mysqld_safe&
See http://dev.mysql.com/doc/mysql/en/mysqld-safe.html for more information
ERROR! The server quit without updating PID file (/data/percona/mysql.pid).
重启后也报错
ERROR! MySQL (Percona Server) PID file could not be found!
Starting MySQL (Percona Server).170308 18:46:54 mysqld_safe The file /usr/local/Percona-Server-5.6.35-rel80.0-Linux.x86_64.ssl101/bin/mysqld
does not exist or is not executable. Please cd to the mysql installation
directory and restart this script from there as follows:
./bin/mysqld_safe&
See http://dev.mysql.com/doc/mysql/en/mysqld-safe.html for more information
ERROR! The server quit without updating PID file (/data/percona/mysql.pid).
Please login or Register to submit your answer