[英]DBI connect('database=orthomcl;host=db;mysql_local_infile=1','orthomcl',…) failed: Access denied for user
我有cat orthomcl/Dockerfile
:
FROM debian:stretch-backports
RUN apt-get update && apt-get install -y --no-install-recommends \
wget \
cpanminus \
build-essential \
default-libmysqlclient-dev \
python \
ca-certificates \
&& rm -rf /var/lib/apt/lists/*
RUN cpanm DBI DBD::mysql
這是我docker-compose.yml
:
orthomcl:
tty: true
build: orthomcl
restart: always
links:
- db
volumes:
- ./output_dir/:/output_dir
db:
image: mariadb
restart: always
environment:
- MYSQL_ROOT_PASSWORD="PAssw0rd"
- MYSQL_DATABASE="orthomcl"
- MYSQL_USER="orthomcl"
- MYSQL_PASSWORD="PAssw0rd"
ports:
- "3306:3306"
volumes:
- ./mysql/:/docker-entrypoint-initdb.d
這是SQL配置文件:
$ cat mysql/orthomcl.sql
CREATE DATABASE IF NOT EXISTS `orthomcl`;
create user `orthomcl`@`db` identified by 'PAssw0rd';
GRANT ALL PRIVILEGES on `orthomcl`.* to `orthomcl`@`db`;
連接到數據庫的Perl腳本是output_dir/test.pl
#!/bin/env perl
use DBI;
require DBD::mysql;
my $dbConnectString="DBI:mysql:database=orthomcl;host=db;mysql_local_infile=1";
my $dbLogin="orthomcl";
my $dbPassword="PAssw0rd";
DBI->connect($dbConnectString, $dbLogin, $dbPassword, { RaiseError => 1 } ) or
die ( "Couldn't connect to database: " . DBI->errstr );
接下來,我使用了docker-compose up
,之后我做了:
$ docker-compose run orthomcl perl /output_dir/test.pl
Starting orthomcl_db_1 ... done
DBI connect('database=orthomcl;host=db;mysql_local_infile=1','orthomcl',...) failed: Access denied for user 'orthomcl'@'172.17.0.4' (using password: YES) at /output_dir/test.pl line 10.
MySQL日志顯示:
...
db_1 | 2019-05-04 4:56:31 0 [Note] mysqld: ready for connections.
db_1 | Version: '10.3.14-MariaDB-1:10.3.14+maria~bionic' socket: '/var/run/mysqld/mysqld.sock' port: 3306 mariadb.org binary distribution
db_1 | 2019-05-04 4:58:19 8 [Warning] Access denied for user 'orthomcl'@'172.17.0.4' (using password: YES)
如何解決上述錯誤?
先感謝您。
導致錯誤的原因是您的數據庫無法解析客戶端的IP地址“172.17.0.4”,返回到您用於帳戶的主機名“db”。 如果您想要像這樣工作,您需要在docker環境中提供強大的前向和后向域名解析。
或者,如果您對Docker環境(以及它使用的專用IP范圍)充分屏蔽外部訪問感到高興,您可以完全放棄將帳戶限制為特定客戶端地址的想法,並為主機使用“%”通配符部分。 如果這是您的方法,您可能還需要在數據庫服務器配置中添加“--skip-name-resolve”,以便連接不會觸發無用的DNS查詢和可能的延遲。
不完全確定docker文件設置但錯誤是:
用戶'orthomcl'@'172.17.0.4'拒絕訪問(使用密碼:是)
所以授予知識產權,范圍(172.%)或全部
create user `orthomcl`@`%` identified by 'PAssw0rd';
GRANT ALL PRIVILEGES on `orthomcl`.* to `orthomcl`@`%`;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.