请参阅下面的编辑,我留下原始问题以帮助其他人。
我尝试通过 Apps 脚本和 JDBC 连接到本地 MySQL 服务器,但我不断收到两个错误之一。这段代码:
function connectTest() {
var conn = Jdbc.getConnection("jdbc:mysql://localhost", "root", "xxx");
}
给出的错误为Failed to establish a database connection. Check connection string, username and password.
这段代码:
function connectTest() {
var conn = Jdbc.getConnection("jdbc:mysql://localhost:3306", "xxx", "pass");
}
给出的错误为Invalid argument: url
.
我已经尝试了数十种组合,但无法使其发挥作用。从 Apps 脚本登录的尝试不会显示在 MySQL 的访问日志上(即,如果我尝试使用错误的信息在本地登录,我会看到[Note] Access denied for user 'host'@'localhost' (using password: YES)
。我已授予 root 适当的访问权限:
mysql> show grants for 'root'@'%';
+-------------------------------------------------------------+
| Grants for root@% |
+-------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION |
+-------------------------------------------------------------+
1 row in set (0.00 sec)
我是否需要做其他事情才能将本地数据库公开到互联网/Google Apps 脚本?
EDIT:
我现在可以从 MySQL 日志中获取访问被拒绝的注释(例如Access denied for user 'root'@'12.123.12.123' (using password: YES)
),但应用程序仍然无法连接。我尝试添加bind-address
使用我的公共 IP,但 MySQL 无法启动,我得到([ERROR] Can't start server: Bind on TCP/IP port: Can't assign requested address
)
function connectTest() {
var conn = Jdbc.getConnection("jdbc:mysql://12.123.12.123:3306", "root", "xxx");
}
编辑2:我更改了bind-address=0.0.0.0,这确实允许我在数据库日志中收到拒绝访问错误,但仍然无法连接。我已成功连接到互联网上其他开放的 MySQL 数据库(例如 ensemldb.ensembl.org:3306),但我仍然无法连接到本地数据库。