How to install mysql in docker

How to install mysql in docker

I recently deployed Django and didn't want to install MySQL manually, so I tried to use Docker. I summarized the installation experience. These prerequisites are after installing Docker:

1. View the mysql image;

 docker search mysql 

2. If there is an image, pull the latest image directly

docker pull mysqlv:latest

3. Start the mysql image

```shell
docker run –name w-mysql -e MYSQL_ROOT_PASSWORD=123456 -p 3306:3306 -d mysql:latest

–name: Name the newly created container, here named w-mysql

-e: Configuration information, here configure the login password of the mysql root user
-p: port mapping, which means that port 3306 is used in this container. The second port mapped to the local machine is also 3306.
-d: Output the full ID of the container after successfully starting the container

4. Log in to mysql

```shell
docker exec -it w-mysql mysql -uroot -p 

5. Create a user who can connect remotely

create user 'tantan404' identified with mysql_native_password by '123456';
grant all privileges on *.* to 'tantan404';

6. Try to connect using Navicat

7. Possible Errors

This error may be reported when connecting because the encryption rule of the new version of MySQL is not supported. The encryption rule in versions before MySQL 8 is mysql_native_password, and after MySQL 8, the encryption rule is caching_sha2_password. There are two ways to solve the problem. One is to upgrade the navicat driver, and the other is to restore the encryption rule of the MySQL user login password to mysql_native_password. I used the second method:
The operation is as follows:

ALTER USER 'root'@'%' IDENTIFIED BY 'password' PASSWORD EXPIRE NEVER; #Modify the encryption rule, 'password' is your password ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'password'; #Update the user's password, 'password' is your password FLUSH PRIVILEGES; #Refresh permissions

8. End

Simple mysql installation based on docker, make a record

The above is the details of how to install MySQL in docker. For more information about installing MySQL in docker, please pay attention to other related articles on 123WORDPRESS.COM!

You may also be interested in:
  • How to install MySQL and Redis in Docker
  • Detailed steps for installing Tomcat, MySQL and Redis with Docker
  • Tutorial on installing MySQL with Docker and implementing remote connection
  • How to install MySQL 8.0 in Docker
  • Docker installation of MySQL (8 and 5.7)
  • How to install MySQL and MariaDB in Docker
  • How to install common components (mysql, redis) in Docker
  • How to install MySQL8 in Docker
  • Docker installation and configuration steps for MySQL

<<:  Vue.js uses Element-ui to implement the navigation menu

>>:  How to use DCL to manage users and control permissions in MySQL

Recommend

How to solve the margin collapse problem in CSS

First, let's look at three situations where m...

MySQL 8.0.18 installation tutorial under Windows (illustration)

Download Download address: https://dev.mysql.com/...

TypeScript uses vscode to monitor the code compilation process

Install Install ts command globally npm install -...

Analysis of rel attribute in HTML

.y { background: url(//img.jbzj.com/images/o_y.pn...

Change the MySQL database engine to InnoDB

PS: I use PHPStudy2016 here 1. Stop MySQL during ...

js implements table drag options

This article example shares the specific code of ...

What is Software 404 and 404 Error and what is the difference between them

First of all, what is 404 and soft 404? 404: Simpl...

How to change the Ali source in Ubuntu 20.04

Note that this article does not simply teach you ...

How to develop uniapp using vscode

Because I have always used vscode to develop fron...

Is the tag li a block-level element?

Why can it set the height, but unlike elements lik...

Detailed explanation of MySQL remote connection permission

1. Log in to MySQL database mysql -u root -p View...

How to set up a shared folder on a vmware16 virtual machine

1. Set up a shared folder on the virtual machine:...

Introduction to setting up Tomcat to start automatically on Linux system

1. Enter the /etc/init.d directory: cd /etc/init....

Basic usage of wget command under Linux

Table of contents Preface 1. Download a single fi...