5

我正在尝试配置 nodejs 容器以连接到 mysql 数据库。

我的代码如下所示:

var pool  = mysql.createPool({
    host     : 'mysql',
    port     : '3306',
    user     : 'root',
    password : '...',
    database : 'general',
    connectionLimit : 50,
    queueLimit : 5000
});

我正在使用标准的mysql容器。

我正在使用 fig 来启动容器。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 db。

谢谢!

编辑 所以,我最终找到了答案。这个问题确实是一个特权问题。我运行了以下命令:

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'password'

我能够访问数据库。

4

1 回答 1

0

我使用 drakedroid/mysql-with-data ( https://registry.hub.docker.com/u/drakedroid/mysql-with-data/ ) 图像。它扩展了默认图像,但添加了更多功能。

于 2015-03-19T14:56:28.320 回答