Docker mysql主机没有特权

Pet*_*tru 5 mysql node.js docker fig

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

我的代码看起来像这样:

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

我正在使用标准的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: ...
Run Code Online (Sandbox Code Playgroud)

每次我尝试连接时都会收到以下错误:

failed to connect to database: Error: ER_HOST_NOT_PRIVILEGED: Host '172.17.0.142' is not allowed to connect to this MySQL server
Run Code Online (Sandbox Code Playgroud)

知道我做错了什么吗?我玩过wordpress,似乎连接到同一个mysql db没有任何问题.

谢谢!

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

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'password'
Run Code Online (Sandbox Code Playgroud)

我能够访问数据库.

Pie*_*ter 0

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