Answers: <p>Solution:</p>
  <pre><code>root $ 
  root $ mysql -h localhost -P 3306 --protocol=tcp -u user -p
  Enter password: 
  Welcome to the MySQL monitor.  Commands end with ; or \g.
  Your MySQL connection id is 17
  Server version: 8.0.21 MySQL Community Server - GPL
  
  Copyright (c) 2000, 2020, 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&gt; 
  mysql&gt; SELECT host, user FROM mysql.user;
  +-----------+------------------+
  | host      | user             |
  +-----------+------------------+
  | %         | user             |
  | localhost | healthchecker    |
  | localhost | mysql.infoschema |
  | localhost | mysql.session    |
  | localhost | mysql.sys        |
  | localhost | root             |
  +-----------+------------------+
  6 rows in set (0.00 sec)
  
  mysql&gt; 
  </code></pre>
  <p>per:</p>
  <p><a href="https://stackoverflow.com/q/33001750/4531180">https://stackoverflow.com/q/33001750/4531180</a></p>
  
Answers: CC BY-SA 4.0
Answers: 2020-09-21T14:02:18.863Z
Answers: 2020-09-21T14:08:01.893Z
Answers: 2020-09-21T14:08:01.893Z
Answers: Nicholas Saunders
Body: <p>I thought I had this working a few minutes ago:</p>
  <pre><code>root $ 
  root $ docker container ls
  CONTAINER ID        IMAGE                       COMMAND                  CREATED             STATUS                   PORTS                               NAMES
  9eb4a18def01        mysql/mysql-server:latest   &quot;/entrypoint.sh mysq…&quot;   6 minutes ago       Up 6 minutes (healthy)   0.0.0.0:3306-&gt;3306/tcp, 33060/tcp   mysql
  root $ 
  root $ mysql -u root -p
  Enter password: 
  ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
  root $ 
  root $ docker exec -ti --user root mysql bash
  bash-4.2# 
  bash-4.2# mysql -u root -p
  Enter password: 
  Welcome to the MySQL monitor.  Commands end with ; or \g.
  Your MySQL connection id is 16
  Server version: 8.0.21 MySQL Community Server - GPL
  
  Copyright (c) 2000, 2020, 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&gt; 
  mysql&gt; SELECT host, user FROM mysql.user;
  +-----------+------------------+
  | host      | user             |
  +-----------+------------------+
  | localhost | healthchecker    |
  | localhost | mysql.infoschema |
  | localhost | mysql.session    |
  | localhost | mysql.sys        |
  | localhost | root             |
  +-----------+------------------+
  5 rows in set (0.00 sec)
  
  mysql&gt; 
  mysql&gt; CREATE USER 'user'@'%' IDENTIFIED BY 'password';
  Query OK, 0 rows affected (0.09 sec)
  
  mysql&gt; 
  mysql&gt; GRANT ALL PRIVILEGES ON *.* TO 'user'@'%' WITH GRANT OPTION;
  Query OK, 0 rows affected (0.13 sec)
  
  mysql&gt; 
  mysql&gt; FLUSH PRIVILEGES;
  Query OK, 0 rows affected (0.05 sec)
  
  mysql&gt; 
  mysql&gt; SELECT host, user FROM mysql.user;
  +-----------+------------------+
  | host      | user             |
  +-----------+------------------+
  | %         | user             |
  | localhost | healthchecker    |
  | localhost | mysql.infoschema |
  | localhost | mysql.session    |
  | localhost | mysql.sys        |
  | localhost | root             |
  +-----------+------------------+
  6 rows in set (0.00 sec)
  
  mysql&gt; 
  mysql&gt; exit
  Bye
  bash-4.2# 
  bash-4.2# mysql -u user -p
  Enter password: 
  Welcome to the MySQL monitor.  Commands end with ; or \g.
  Your MySQL connection id is 21
  Server version: 8.0.21 MySQL Community Server - GPL
  
  Copyright (c) 2000, 2020, 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&gt; 
  mysql&gt; exit
  Bye
  bash-4.2#   
  bash-4.2# exit
  exit
  root $ 
  root $ mysql -u user -p
  Enter password: 
  ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
  root $ 
  </code></pre>
  <p>but clearly not.  How do I check that the container connection is accessible?  I'm trying:</p>
  <pre><code>root $ 
  root $ telnet 127.0.0.1 3306
  Trying 127.0.0.1...
  Connected to 127.0.0.1.
  Escape character is '^]'.
  J
  8.0.21%#%T:/]T�e-r&amp;UR([/caching_sha2_password
  ^CConnection closed by foreign host.
  root $ 
  root $ 
  root $ telnet 127.0.0.1 33060
  Trying 127.0.0.1...
  telnet: Unable to connect to remote host: Connection refused
  root $ 
  </code></pre>
  <p>but that seems a bit odd.</p>
  
Comments: CC BY-SA 4.0
Comments: 2020-09-21T12:45:17.103Z
Comments: see also:  https://github.com/docker-library/mysql/issues/275
Comments: Nicholas Saunders
Tags: <docker><containers><databases><images><mysql>
Title: How to gain console access to a MySQL server running on a docker container from the host?
UserDisplayName: Nicholas Saunders
ThreadText: # How to gain console access to a MySQL server running on a docker container from the host?
  
  (Asked by: username_0 on 2020-09-21)
  
  I thought I had this working a few minutes ago:
  
  ```
  root $ 
  root $ docker container ls
  CONTAINER ID        IMAGE                       COMMAND                  CREATED             STATUS                   PORTS                               NAMES
  9eb4a18def01        mysql/mysql-server:latest   "/entrypoint.sh mysq…"   6 minutes ago       Up 6 minutes (healthy)   0.0.0.0:3306->3306/tcp, 33060/tcp   mysql
  root $ 
  root $ mysql -u root -p
  Enter password: 
  ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
  root $ 
  root $ docker exec -ti --user root mysql bash
  bash-4.2# 
  bash-4.2# mysql -u root -p
  Enter password: 
  Welcome to the MySQL monitor.  Commands end with ; or \g.
  Your MySQL connection id is 16
  Server version: 8.0.21 MySQL Community Server - GPL
  
  Copyright (c) 2000, 2020, 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> 
  mysql> SELECT host, user FROM mysql.user;
  +-----------+------------------+
  | host      | user             |
  +-----------+------------------+
  | localhost | healthchecker    |
  | localhost | mysql.infoschema |
  | localhost | mysql.session    |
  | localhost | mysql.sys        |
  | localhost | root             |
  +-----------+------------------+
  5 rows in set (0.00 sec)
  
  mysql> 
  mysql> CREATE USER 'user'@'%' IDENTIFIED BY 'password';
  Query OK, 0 rows affected (0.09 sec)
  
  mysql> 
  mysql> GRANT ALL PRIVILEGES ON *.* TO 'user'@'%' WITH GRANT OPTION;
  Query OK, 0 rows affected (0.13 sec)
  
  mysql> 
  mysql> FLUSH PRIVILEGES;
  Query OK, 0 rows affected (0.05 sec)
  
  mysql> 
  mysql> SELECT host, user FROM mysql.user;
  +-----------+------------------+
  | host      | user             |
  +-----------+------------------+
  | %         | user             |
  | localhost | healthchecker    |
  | localhost | mysql.infoschema |
  | localhost | mysql.session    |
  | localhost | mysql.sys        |
  | localhost | root             |
  +-----------+------------------+
  6 rows in set (0.00 sec)
  
  mysql> 
  mysql> exit
  Bye
  bash-4.2# 
  bash-4.2# mysql -u user -p
  Enter password: 
  Welcome to the MySQL monitor.  Commands end with ; or \g.
  Your MySQL connection id is 21
  Server version: 8.0.21 MySQL Community Server - GPL
  
  Copyright (c) 2000, 2020, 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> 
  mysql> exit
  Bye
  bash-4.2#   
  bash-4.2# exit
  exit
  root $ 
  root $ mysql -u user -p
  Enter password: 
  ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
  root $ 
  
  ```
  
  but clearly not. How do I check that the container connection is accessible? I'm trying:
  
  ```
  root $ 
  root $ telnet 127.0.0.1 3306
  Trying 127.0.0.1...
  Connected to 127.0.0.1.
  Escape character is '^]'.
  J
  8.0.21%#%T:/]T�e-r&UR([/caching_sha2_password
  ^CConnection closed by foreign host.
  root $ 
  root $ 
  root $ telnet 127.0.0.1 33060
  Trying 127.0.0.1...
  telnet: Unable to connect to remote host: Connection refused
  root $ 
  
  ```
  
  but that seems a bit odd.
  
  **Tags:** docker, containers, databases, images, mysql
  
  > **Comments:**
  > **username_0**: see also:  https://github.com/docker-library/mysql/issues/275  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2020-09-21. Score: 2
  
  Solution:
  
  ```
  root $ 
  root $ mysql -h localhost -P 3306 --protocol=tcp -u user -p
  Enter password: 
  Welcome to the MySQL monitor.  Commands end with ; or \g.
  Your MySQL connection id is 17
  Server version: 8.0.21 MySQL Community Server - GPL
  
  Copyright (c) 2000, 2020, 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> 
  mysql> SELECT host, user FROM mysql.user;
  +-----------+------------------+
  | host      | user             |
  +-----------+------------------+
  | %         | user             |
  | localhost | healthchecker    |
  | localhost | mysql.infoschema |
  | localhost | mysql.session    |
  | localhost | mysql.sys        |
  | localhost | root             |
  +-----------+------------------+
  6 rows in set (0.00 sec)
  
  mysql> 
  
  ```
  
  per:
  
  <https://stackoverflow.com/q/33001750/4531180>
  
  
  ---
  
  