Dockerで動かしているMySQLに接続ができず、以下エラーが表示されてしまいます
MYSQLのバージョンは5.7.3
PHPは5.16かと思われます
発生している問題・エラーメッセージ
Severity: Warning Message: mysqli::real_connect(): (HY000/1045): Access denied for user 'testuser'@'172.18.0.15' (using password: YES) Filename: mysqli/mysqli_driver.php Line Number: 202
ソースコード
mysqli/mysqli_driver.php Line Number: 202は以下のようになっております
if ($this->_mysqli->real_connect($hostname, $this->username, $this->password, $this->database, $port, $socket, $client_flags)) { // Prior to version 5.7.3, MySQL silently downgrades to an unencrypted connection if SSL setup fails if ( ($client_flags & MYSQLI_CLIENT_SSL) && version_compare($this->_mysqli->client_info, '5.7.3', '<=') && empty($this->_mysqli->query("SHOW STATUS LIKE 'ssl_cipher'")->fetch_object()->Value) ) { $this->_mysqli->close(); $message = 'MySQLi was configured for an SSL connection, but got an unencrypted connection instead!'; log_message('error', $message); return ($this->db->db_debug) ? $this->db->display_error($message, '', TRUE) : FALSE; } return $this->_mysqli; } return FALSE; }
その他
docker-compose.yml
version: '2' services: db_data: image: busybox volumes: - /var/lib/mysql mysql: build: ./config/mysql/ command: mysqld --character-set-server=utf8 --collation-server=utf8_general_ci environment: MYSQL_ROOT_PASSWORD: root MYSQL_DATABASE: "localdb" MYSQL_USER: "localuser" MYSQL_PASSWORD: "root" TZ: "Asia/Tokyo" ports: - "3306:3306" volumes: - ./sql:/docker-entrypoint-initdb.d volumes_from: - db_data container_name: local_mysql56_cc networks: default: external: name: common_link
DB_Driver.php(恐らくDB接続については、ここで設定しているかと思われます。かなり長文のため、最初のinitalizeのみ抜粋)
abstract class CI_DB_driver { /** * Data Source Name / Connect string * * @var string */ public $dsn; /** * Username * * @var string */ public $username; /** * Password * * @var string */ public $password; /** * Hostname * * @var string */ public $hostname; /** * Database name * * @var string */ public $database; /** * Database driver * * @var string */ public $dbdriver = 'mysqli'; /** * Sub-driver * * @used-by CI_DB_pdo_driver * @var string */ public $subdriver; /** * Table prefix * * @var string */ public $dbprefix = ''; /** * Character set * * @var string */ public $char_set = 'utf8'; /** * Collation * * @var string */ public $dbcollat = 'utf8_general_ci'; /** * Encryption flag/data * * @var mixed */ public $encrypt = FALSE; /** * Swap Prefix * * @var string */ public $swap_pre = ''; /** * Database port * * @var int */ public $port = ''; /** * Persistent connection flag * * @var bool */ public $pconnect = FALSE; /** * Connection ID * * @var object|resource */ public $conn_id = FALSE; /** * Result ID * * @var object|resource */ public $result_id = FALSE; /** * Debug flag * * Whether to display error messages. * * @var bool */ public $db_debug = FALSE; /** * Benchmark time * * @var int */ public $benchmark = 0; /** * Executed queries count * * @var int */ public $query_count = 0; /** * Bind marker * * Character used to identify values in a prepared statement. * * @var string */ public $bind_marker = '?'; /** * Save queries flag * * Whether to keep an in-memory history of queries for debugging purposes. * * @var bool */ public $save_queries = TRUE; /** * Queries list * * @see CI_DB_driver::$save_queries * @var string[] */ public $queries = array(); /** * Query times * * A list of times that queries took to execute. * * @var array */ public $query_times = array(); /** * Data cache * * An internal generic value cache. * * @var array */ public $data_cache = array(); /** * Transaction enabled flag * * @var bool */ public $trans_enabled = TRUE; /** * Strict transaction mode flag * * @var bool */ public $trans_strict = TRUE; /** * Transaction depth level * * @var int */ protected $_trans_depth = 0; /** * Transaction status flag * * Used with transactions to determine if a rollback should occur. * * @var bool */ protected $_trans_status = TRUE; /** * Transaction failure flag * * Used with transactions to determine if a transaction has failed. * * @var bool */ protected $_trans_failure = FALSE; /** * Cache On flag * * @var bool */ public $cache_on = FALSE; /** * Cache directory path * * @var bool */ public $cachedir = ''; /** * Cache auto-delete flag * * @var bool */ public $cache_autodel = FALSE; /** * DB Cache object * * @see CI_DB_cache * @var object */ public $CACHE; /** * Protect identifiers flag * * @var bool */ protected $_protect_identifiers = TRUE; /** * List of reserved identifiers * * Identifiers that must NOT be escaped. * * @var string[] */ protected $_reserved_identifiers = array('*'); /** * Identifier escape character * * @var string */ protected $_escape_char = '"'; /** * ESCAPE statement string * * @var string */ protected $_like_escape_str = " ESCAPE '%s' "; /** * ESCAPE character * * @var string */ protected $_like_escape_chr = '!'; /** * ORDER BY random keyword * * @var array */ protected $_random_keyword = array('RAND()', 'RAND(%d)'); /** * COUNT string * * @used-by CI_DB_driver::count_all() * @used-by CI_DB_query_builder::count_all_results() * * @var string */ protected $_count_string = 'SELECT COUNT(*) AS '; // -------------------------------------------------------------------- /** * Class constructor * * @param array $params * @return void */ public function __construct($params) { if (is_array($params)) { foreach ($params as $key => $val) { $this->$key = $val; } } log_message('info', 'Database Driver Class Initialized'); } // -------------------------------------------------------------------- /** * Initialize Database Settings * * @return bool */ public function initialize() { /* If an established connection is available, then there's * no need to connect and select the database. * * Depending on the database driver, conn_id can be either * boolean TRUE, a resource or an object. */ if ($this->conn_id) { return TRUE; } // ---------------------------------------------------------------- // Connect to the database and set the connection ID $this->conn_id = $this->db_connect($this->pconnect); // No connection resource? Check if there is a failover else throw an error if ( ! $this->conn_id) { // Check if there is a failover set if ( ! empty($this->failover) && is_array($this->failover)) { // Go over all the failovers foreach ($this->failover as $failover) { // Replace the current settings with those of the failover foreach ($failover as $key => $val) { $this->$key = $val; } // Try to connect $this->conn_id = $this->db_connect($this->pconnect); // If a connection is made break the foreach loop if ($this->conn_id) { break; } } } // We still don't have a connection? if ( ! $this->conn_id) { log_message('error', 'Unable to connect to the database'); if ($this->db_debug) { $this->display_error('db_unable_to_connect'); } return FALSE; } } // Now we set the character set and that's all return $this->db_set_charset($this->char_set); }
試したこと
GRANT ALL ON test* to ‘testuser’@‘%’ IDENTIFIED BY ‘root’; でユーザー作成
回答1件
あなたの回答
tips
プレビュー