Home >Database >Mysql Tutorial >How to solve Docker MySQL cannot be accessed by the host

How to solve Docker MySQL cannot be accessed by the host

WBOY
WBOYforward
2023-05-26 13:55:061611browse

1 Problem description

DockerAfter starting the MySQL container, create a localhost access user:

create user test@localhost identified by 'test';

However, the user cannot log in through the host machine:

mycli -u test

How to solve Docker MySQL cannot be accessed by the host

2 Reason

MySQL# in Docker ##The user who created localhost can only be accessed within Docker and cannot be accessed externally.

As for why

root can be accessed on the host machine, it is because there are two root by default, which are:

  • root@localhost

  • root@%

How to solve Docker MySQL cannot be accessed by the host# #And

test

has only one localhost:

How to solve Docker MySQL cannot be accessed by the host3 Solution

Create

test@%

Or create test@172.17.0.1: <pre class="brush:sql;">create user test@% identified by &amp;#39;test&amp;#39;; create user test@172.17.0.1 identified by &amp;#39;test&amp;#39;;</pre>

The above is the detailed content of How to solve Docker MySQL cannot be accessed by the host. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete