Docker connects to the host Mysql operation

Docker connects to the host Mysql operation

Today, the company project needs to configure docker. After successfully installing it on Windows, I found that I could not connect to the local mysql.

I keep reporting permission issues or wrong addresses.

Finally found

1: The address is according to the following ipv4

2: To open the localhost permission on the host Mysql, the command is as follows

mysql -u root -pvmwaremysql>use mysql;

mysql>update user set host = '%' where user = 'root';

mysql>select host, user from user;

Okay, that’s it.

Additional knowledge: The Docker database container cannot be accessed locally, but can be accessed remotely

Preface

In the past, when I used idea to connect to the docker database on the Alibaba Cloud server, I used the server IP and port number. Later, I felt that the open port number of the security group was not safe, and wanted to use localhost, but found that I could not connect.

I thought I could only use the server IP and not localhost, but then I suddenly discovered that each Docker container has its own IP.

1. Enter the container

docker exec -it 8f00a625f3fb bash

2. Check IP

cat /etc/hosts

You can see that my IP is 172.18.0.2

3. Modify the link address

It worked after that.

The above docker connection host Mysql operation is all the content that the editor shares with you. I hope it can give you a reference. I also hope that you will support 123WORDPRESS.COM.

You may also be interested in:
  • Docker container time zone adjustment operation
  • Solve the problem that docker run or docker restart will automatically exit when starting the image
  • Use nexus as a private library to proxy docker to upload and download images
  • Docker uses the nsenter tool to enter the container
  • Docker executes a command in a container outside the container
  • Solve the error during connect exception in Docker

<<:  Detailed explanation of mysql user variables and set statement examples

>>:  DOCTYPE type detailed introduction

Recommend

Linux View File System Type Example Method

How to check the file system type of a partition ...

Compile CPP files using G++ in Ubuntu

When I used g++ to compile the cpp file for the f...

MySQL installation and configuration methods and precautions under Windows platform

2.1、msi installation package 2.1.1、Installation I...

vue-element-admin global loading waiting

Recent requirements: Global loading, all interfac...

Detailed explanation of meta tags (the role of meta tags)

No matter how wonderful your personal website is,...

XHTML Web Page Tutorial

This article is mainly to let beginners understan...

MySQL's conceptual understanding of various locks

Optimistic Locking Optimistic locking is mostly i...

React implements multi-component value transfer function through conetxt

The effect of this function is similar to vue的pro...

Cleverly use CSS3's webkit-box-reflect to achieve various dynamic effects

In an article a long time ago, I talked about the...

The whole process of installing and configuring Harbor1.7 on CentOS7.5

1. Download the required packages wget -P /usr/lo...

MySQL free installation version configuration tutorial

This article shares the MySQL free installation c...

In-depth understanding of MySQL self-connection and join association

1. MySQL self-connection MySQL sometimes needs to...

Test and solution for MySQL's large memory usage and high CPU usage

After the changes: innodb_buffer_pool_size=576M -...

HTML table tag tutorial (12): border style attribute FRAME

Use the FRAME property to control the style type ...

MySQL uses inet_aton and inet_ntoa to process IP address data

This article will introduce how to save IP addres...