connection failed between two linked containers : apache2/php & mysql

Medone :

for my two containers:

Container 1:

        - name: boxoffice
        - containerPort : 80
        - hostPort: 3030
        - service installed : apache2 and php

command run container 1:

docker run  --name=boxoffice -p 3030:80 -v /Users/mac/Desktop/storage-web:/var/www/app -d  --link=db medoneapache:latest

Container 2:

        - name: db
        - containerPort : 3306
        - hostPort: 3306
        - service installed : mysql

command run container 2:

docker run --name=db -p 3306:3306   -v /Users/mac/Desktop/storage-db:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=medone -d  mysqlmedone:1.0

i linked the first container "boxoffice" to the second container "db" via --link=db

and i create a php file to test the mysql connection that having a database called : profil

connection-php-mysql.php (/var/www/app) in "boxoffice" container:

<?php
$servername = "db";
$username = "root";
$password = "medone";

// Create connection
$conn = mysqli_connect($servername, $username, $password);

// Check connection
if (!$conn) {
    die("Connection failed: " . mysqli_connect_error());
}
echo "Connected successfully";
?>

Here is the error that i got :

Warning: mysqli_connect(): The server requested authentication method unknown to the client [caching_sha2_password] in /var/www/app/index.php on line 7

Warning: mysqli_connect(): (HY000/2054): The server requested authentication method unknown to the client in /var/www/app/index.php on line 7 Connection failed: The server requested authentication method unknown to the client

i inspected the first container to get the host ip address : 172.17.0.2 and replaced it with db as servername but i got the same error

and i can't get the username as root getting the error:

mysql -u root

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

Dharman :

You need to upgrade to PHP 7.4.4.

The support for caching_sha2_password has been added both in mysqli and PDO only in PHP 7.4.4.

The relevant feature-request: https://bugs.php.net/bug.php?id=79275
The GitHub PR: https://github.com/php/php-src/pull/5210

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=402112&siteId=1