Запуск в MAC OS.
Следуя этим Базовым шагам для развертывания MySQL Server с Docker , я пытаюсь установить соединение с контейнером через базу данных php storm.
И я получаю ошибку ниже на картинке:
![enter image description here](https://i.stack.imgur.com/EqEQr.png)
Я могу получить к ней доступ через терминал:
docker exec -it 0ed bash
bash-4.2# mysql -uroot -pdockerLocal
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 47
Server version: 5.7.25 MySQL Community Server (GPL)
Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
| testdb |
+--------------------+
5 rows in set (0.00 sec)
mysql>
В порту 3306 не запущен процесс. netstat -vanp tcp | grep 3306
ничего не показывает.
И мой Laravel также не может подключиться к серверу db.
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=testdb
DB_USERNAME=root
DB_PASSWORD=dockerLocal
Это информация о контейнере:
docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
0edce223c684 mysql/mysql-server:5.7 "/entrypoint.sh mysq…" 34 minutes ago Up 34 minutes (healthy) 3306/tcp, 33060/tcp stupefied_johnson
Как я могу проверить это соединение и как я могу работать с подключением phpstorm db?
UPDATE
После того, как порт открыт (была проблема), мы не можем подключиться к контейнеру, используя root@localhost
.
SELECT host, user FROM mysql.user;
+-----------+---------------+
| host | user |
+-----------+---------------+
| localhost | healthchecker |
| localhost | mysql.session |
| localhost | mysql.sys |
| localhost | root |
+-----------+---------------+
Это ошибка:
Connection to @0.0.0.0 failed.
[HY000][1130] null, message from server: "Host '172.17.0.1' is not allowed to connect to this MySQL server"
Решение здесь в этом посте .
Check if the database user exists and can connect
In MySQL, each database user is defined with IP address in it, so you can have for example a root user allowed to connect from localhost (127.0.0.1) but not from other IP addresses. With a container, you never access to the database from 127.0.0.1, it could explain the problem.
Короче говоря, это работает, если я делаю так:
CREATE USER 'jerry'@'%' IDENTIFIED BY 'jerrypassword';
SELECT host, user FROM mysql.user;
+-----------+---------------+
| host | user |
+-----------+---------------+
| % | jerry |
| localhost | healthchecker |
| localhost | mysql.session |
| localhost | mysql.sys |
| localhost | root |
+-----------+---------------+