我有一台装有 Ubuntu 系统的 Azure 虚拟机,带有 MySQL 服务器,我想从 Web 应用程序访问数据库。当我安装 mysql-server 时,我执行了
$ iptables -I INPUT -p tcp --dport 3306 -m state --state NEW,ESTABLISHED -j ACCEPT
$ iptables -I OUTPUT -p tcp --sport 3306 -m state --state ESTABLISHED -j ACCEPT
Run Code Online (Sandbox Code Playgroud)
允许 tcp 连接。在/etc/mysql/my.cnf我添加的文件中bind-address = 168.63.178.87,这是 Azure 面板告诉我的“虚拟 IP 地址”。
在 mysql 中,我用来连接的用户拥有所需数据库的所有权限(我认为):
mysql> SHOW GRANTS FOR 'user'@'%';
+-------------------------------------------------------------------------------------------------------------------+
| Grants for user@% |
+-------------------------------------------------------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'user'@'%' IDENTIFIED BY PASSWORD 'pass_ommited' | …Run Code Online (Sandbox Code Playgroud)