Detailed explanation of Deepin using docker to install mysql database

Detailed explanation of Deepin using docker to install mysql database

Query the MySQL source first

docker search mysql

You can also go to the official website to view the image tag and select the version you need, otherwise the latest version will be downloaded: https://hub.docker.com/_/mysql/
Then an error was reported! ! !

root@deepin-PC:/etc/apt# docker pull mysql:8.0.11
Error response from daemon: Get https://registry-1.docker.io/v2/library/mysql/manifests/8.0.11: Get https://auth.docker.io/token?scope=repository%3Alibrary%2Fmysql%3Apull&service=registry.docker.io: net/http: TLS handshake timeout

Switch to a domestic mirror source

echo "DOCKER_OPTS=\"\$DOCKER_OPTS --registry-mirror=http://f2d6cb40.m.daocloud.io\"" | sudo tee -a /etc/default/docker

Restart Docker

sudo service docker restart

Try again

root@deepin-PC:/etc/docker# docker pull mysql:8.0.11
8.0.11: Pulling from library/mysql
be8881be8156: Pull complete
c3995dabd1d7: Pull complete
9931fdda3586: Pull complete
bb1b6b6eff6a: Pull complete
a65f125fa718: Pull complete
2d9f8dd09be2: Pull complete
37b912cb2afe: Pull complete
90a9e6fd6a27: Pull complete
959ebd3ef120: Pull complete
5eda665eddc4: Pull complete
d9007173a367: Pull complete
239f4d989075: Pull complete
Digest: sha256:ffa442557c7a350939d9cd531f77d6cbb98e868aeb4a328289e0e5469101c20e
Status: Downloaded newer image for mysql:8.0.11
docker.io/library/mysql:8.0.11

Verify

root@deepin-PC:/etc/docker# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mysql 8.0.11 5dbe5b6313e1 21 months ago 445MB

Create a folder dedicated to mysql for docker

root@deepin-PC:/etc/docker# cd /opt/
root@deepin-PC:/opt# mkdir mysql_docker
root@deepin-PC:/opt# cd mysql_docker/
root@deepin-PC:/opt/mysql_docker# echo $PWD
/opt/mysql_docker

Start the mysql container

docker run --name mysqlserver -v $PWD/conf:/etc/mysql/conf.d -v $PWD/logs:/logs -v $PWD/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=123456 -d -i -p 3306:3306 mysql:8.0.11

View the complete container ID

cd /var/lib/docker/containers/

View the started container

root@deepin-PC:/opt/mysql_docker# docker ps 
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
1f9aa5b79b6a mysql:latest "docker-entrypoint.s…" About a minute ago Up 59 seconds 0.0.0.0:3306->3306/tcp, 33060/tcp mysql

Enter mysql (you can replace mysql with the container id)

docker exec -it mysql bash


Connect to mysql

mysql -u root -p 123456

Grant remote access permission

mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> select host,user from user;
+-----------+------------------+
| host | user |
+-----------+------------------+
| % | root |
| localhost | mysql.infoschema |
| localhost | mysql.session |
| localhost | mysql.sys |
| localhost | root |
+-----------+------------------+
5 rows in set (0.00 sec)

mysql> ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123456';
Query OK, 0 rows affected (0.02 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)

View the docker log:

root@deepin-PC:/opt/mysql_docker# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
1f9aa5b79b6a mysql:latest "docker-entrypoint.s…" 6 minutes ago Up 6 minutes 0.0.0.0:3306->3306/tcp, 33060/tcp mysql
root@deepin-PC:/opt/mysql_docker# docker logs -f --tail 10 1f9aa5b79b6a
2020-05-11 14:14:30+00:00 [Note] [Entrypoint]: MySQL init process done. Ready for start up.

2020-05-11T14:14:30.702850Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it' is deprecated and will be removed in a future release.
2020-05-11T14:14:30.702952Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.20) started as process 1
2020-05-11T14:14:30.712787Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2020-05-11T14:14:31.064937Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2020-05-11T14:14:31.191792Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Socket: '/var/run/mysqld/mysqlx.sock' bind-address: '::' port: 33060
2020-05-11T14:14:31.284386Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2020-05-11T14:14:31.292565Z 0 [Warning] [MY-011810] [Server] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory.
2020-05-11T14:14:31.312549Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.20' socket: '/var/run/mysqld/mysqld.sock' port: 3306 MySQL Community Server - GPL.

Some common operations

First check the container id

docker ps -a

Find the id

The following id is the container id

Shutdown mysql

docker stop id

Restart

docker restart id

start up

docker start id

**Shut down docker**

systemctl stop docker

Restart Docker

systemctl restart docker

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • How to install mysql database in deepin 2014 system
  • Deepin20.1 system installs MySQL8.0.23 (super detailed MySQL8 installation tutorial)

<<:  Analysis of MySQL user management operation examples

>>:  Vue+Openlayer batch setting flash point implementation code (based on postrender mechanism)

Recommend

Detailed explanation of Nginx log customization and enabling log buffer

Preface If you want to count the source of websit...

Solution to MySQL master-slave delay problem

Today we will look at why master-slave delay occu...

Win7 installation MySQL 5.6 tutorial diagram

Table of contents 1. Download 2. Installation 3. ...

How to use VLAN tagged Ethernet card in CentOS/RHEL system

In some scenarios, we want to assign multiple IPs...

Commonly used JavaScript array methods

Table of contents 1. filter() 2. forEach() 3. som...

Detailed Introduction to the MySQL Keyword Distinct

Introduction to the usage of MySQL keyword Distin...

Example code of how CSS matches multiple classes

CSS matches multiple classes The following HTML t...

Nginx URL rewriting mechanism principle and usage examples

URL rewriting helps determine the preferred domai...

Analysis of MySQL lock mechanism and usage

This article uses examples to illustrate the MySQ...

Detailed explanation of MySQL group sorting to find the top N

MySQL group sorting to find the top N Table Struc...

Briefly explain the use of group by in sql statements

1. Overview Group by means to group data accordin...

Tutorial on installing and uninstalling python3 under Centos7

1. Install Python 3 1. Install dependency package...

Vue uses rules to implement form field validation

There are many ways to write and validate form fi...

In-depth exploration of whether Mysql fuzzy query is case-sensitive

Preface Recently, I have been busy writing a smal...