5
我想配置一个nodejs容器连接到一个MySQL数据库。泊坞窗mysql主机没有特权
我的代码如下所示:
var pool = mysql.createPool({
host : 'mysql',
port : '3306',
user : 'root',
password : '...',
database : 'general',
connectionLimit : 50,
queueLimit : 5000
});
我使用的是标准的
mysql容器
。
我使用无花果来启动容器。 fig.yml看起来像:
node:
build: node
ports:
- "9000:9000"
- "9001:9001"
links:
- mysql:mysql
command: node server/Main.js
mysql:
image: mysql
volumes:
- /data/test:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: ...
每次我尝试连接,我收到以下错误:
failed to connect to database: Error: ER_HOST_NOT_PRIVILEGED: Host '172.17.0.142' is not allowed to connect to this MySQL server
任何想法,我做错了什么?我玩过wordpress,它似乎连接到相同的MySQL数据库没有任何问题。
Thx!
编辑 所以,我最终找到了答案。这个问题确实是一个特权问题。我运行了以下命令:
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'password'
而且我能够访问数据库。
可以[这是帮助](http://stackoverflow.com/questions/19943615/connect-to-remote-mysql-database)?或者可能[这](http://stackoverflow.com/questions/1559955/host-xxx-xx-xxx-xxx-is-not-allowed-to-connect-to-this-mysql-server)? – wassgren 2015-01-09 20:51:56
你的mysql版本是什么?'General'是MySQL 5.6中的一个保留字,在你的池中使用back ticks – Mihai 2015-01-09 20:53:44
@wassgren我不认为这是授权特权问题,因为wordpress连接到同一个数据库没有额外的权限 – Petru 2015-01-09 21:13:17