Docker的mysql主机没有权限 [英] Docker mysql host not privileged
问题描述
我的代码如下所示:
$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $' ,
密码:'...',
数据库:'general',
connectionLimit:50,
queueLimit:5000
});
我正在使用标准的 mysql container。
我正在使用fig来启动容器。 fig.yml看起来像:
node:
build:node
ports:
- 9000:9000
- 9001:9001
链接:
- mysql:mysql
命令:node server / Main.js
mysql:
image:mysql
卷:
- / data / test:/ var / lib / mysql
环境:
MYSQL_ROOT_PASSWORD:...
每次我尝试连接我得到以下错误:
无法连接到数据库:错误:ER_HOST_NOT_PRIVILEGED:主机'172.17.0.142'不允许连接到此MySQL服务器
任何想法我做错了什么?我已经玩过wordpress,似乎连接到同一个mysql数据库没有任何问题。
Thx!
修改
所以,我已经找到答案了。这个问题确实是一个特权问题。我运行以下命令:
授予所有权限*。* TO'root'@'%'IDENTIFIED BY'password'
我可以访问数据库。
我使用drakedroid / mysql-with-data( https://registry.hub.docker.com/u/drakedroid/mysql-with-data/ )图像。它扩展了默认图像,但增加了更多的功能。
I am trying to configure a nodejs container to connect to a mysql database.
My code looks like this:
var pool = mysql.createPool({
host : 'mysql',
port : '3306',
user : 'root',
password : '...',
database : 'general',
connectionLimit : 50,
queueLimit : 5000
});
I am using the standard mysql container.
I am using fig for starting the containers. fig.yml looks something like:
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: ...
Every time i try to connect i get the following error:
failed to connect to database: Error: ER_HOST_NOT_PRIVILEGED: Host '172.17.0.142' is not allowed to connect to this MySQL server
Any idea what I am doing wrong? I have played around with wordpress and it seems to connect to the same mysql db without any problems.
Thx!
Edit So, I have found the answer in the end. The problem was indeed a privilege issue. I ran the following command:
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'password'
And I was able to access the database.
I use the drakedroid/mysql-with-data (https://registry.hub.docker.com/u/drakedroid/mysql-with-data/) image. It extends the default image, but adds more functionality.
这篇关于Docker的mysql主机没有权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!