How to install mysql5.6 in docker under ubuntu

How to install mysql5.6 in docker under ubuntu

1. Install mysql5.6

docker run mysql:5.6

Wait until all items are Download complete and installed

5.6: Pulling from library/mysql
10a267c67f42: Pull complete 
c2dcc7bb2a88: Pull completed 
17e7a0445698: Pull complete 
9a61839a176f: Pull complete 
d4657fda01d9: Pull complete 
c5278a445e5d: Pull complete 
197c0b76f238: Pull complete 
f54c5432bac4: Pull complete 
c26b15abee8a: Pull complete 
80dbe6022c18: Pull complete 
435678c09612: Pull complete 
Digest: sha256:84372107beb1de34bd4673049ea61bc35f374a2b4f19fd5a3abd4d0a2a50b715
Status: Downloaded newer image for mysql:5.6
error: database is uninitialized and password option is not specified 
 You need to specify one of MYSQL_ROOT_PASSWORD, MYSQL_ALLOW_EMPTY_PASSWORD and MYSQL_RANDOM_ROOT_PASSWORD

2. Use a local account to create a folder to map the mysql configuration file in docker

Continue to create 3 folders: conf, data, and logs

My configuration is as follows

val@val-linux:~/docker/mysql1$ pwd
/home/val/docker/mysql1
val@val-linux:~/docker/mysql1$ ls
conf data logs

3. Create a mysql container

Switch to the root account and enter the mysql1 folder you just created

root@val-linux:/home/val# cd /home/val/docker/mysql1/
root@val-linux:/home/val/docker/mysql1#

Create and start a container

docker run -p 33061:3306 --name mysql1 -v $PWD/conf:/etc/mysql -v $PWD/logs:/logs -v $PWD/data:/mysql_data -e MYSQL_ROOT_PASSWORD=123456 -d mysql:5.61
Use the local 33061 port to map the 3306 port of docker and name the container mysql1 
Use local /home/val/docker/mysql1/conf to map mysql conf 
Use local /home/val/docker/mysql1/logs to map mysql logs 
Use local /home/val/docker/mysql1/data to map mysql's mysql_data

Set the root password to 123456

4. Start the mysql container

docker start mysql11

5. Enter mysql bash

docker exec -it mysql1 env LANG=C.UTF-8 bash

Among them, env LANG=C.UTF-8 bash allows the docker command line to support Chinese

6. Copy the configuration file

cp /usr/my.cnf /etc/mysql/my.cnf

7. Log in to mysql

mysql -u root -p

Enter password to enter

8. Check mysql encoding

mysql> show variables like '%character%';
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | latin1 |
| character_set_connection | latin1 |
| character_set_database | latin1 |
| character_set_filesystem | binary |
| character_set_results | latin1 |
| character_set_server | latin1 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.01 sec)

Found that it is not utf-8 encoding

9. Modify mysql encoding

Exit mysql, exit docker

mysql> exit
Bye
root@8b83a30acbf8:/# exit
exit
root@val-linux:/home/val/docker/mysql1#

Modify the my.cnf configuration file

root@val-linux:/home/val/docker/mysql1# vim conf/my.cnf

Press i to enter edit mode

join in

[client] default-character-set=utf8 
[mysql] default-character-set=utf8 
[mysqld] character-set-server=utf8 1
esc :wq! Save and exit

10. Restart mysql in docker and check the code again

root@val-linux:/home/val/docker/mysql1# docker stop mysql1
mysql1
root@val-linux:/home/val/docker/mysql1# docker start mysql1
mysql1
root@val-linux:/home/val/docker/mysql1# docker exec -it mysql1 env LANG=C.UTF-8 bash
root@8b83a30acbf8:/#mysql -u root -p
Enter password: 
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.36 MySQL Community Server (GPL)
Copyright (c) 2000, 2017, 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> show variables like '%character%';
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | latin1 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | latin1 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.00 sec)

11. Create a database

mysql> create database rise;
Query OK, 1 row affected (0.00 sec) 
mysql> use rise;
Database changed

12. Create a user and authorize

mysql> grant all privileges on rise.* to val@'%' identified by '123456';
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

% indicates any IP (IP can be specified), val is the username, 123456 is the password

The above is the method I introduced to you to install mysql5.6 in docker under ubuntu. I hope it will be helpful to you. If you have any questions, please leave me a message and I will reply to you in time!

You may also be interested in:
  • Install and run a MySQL instance on Docker
  • How to install MySQL8 in Docker
  • How to install MySQL 8.0 in Docker
  • Install and use mysql image on docker
  • Docker installation of MySQL (8 and 5.7)
  • Detailed explanation of installing mysql in docker
  • MySQL 8.0.20 installation and configuration tutorial under Docker
  • How to install common components (mysql, redis) in Docker
  • How to install MySQL and MariaDB in Docker
  • Steps to install MySQL using Docker under Linux

<<:  jQuery realizes dynamic particle effect

>>:  Detailed explanation of how to use the canvas operation plugin fabric.js

Recommend

Summary of some HTML code writing style suggestions

Omit the protocol of the resource file It is reco...

MySQL installation and configuration method graphic tutorial (CentOS7)

1. System environment [root@localhost home]# cat ...

Website Design Experience Summary of Common Mistakes in Website Construction

Reminder: Whether it is planning, designing, or de...

Example of how to set up a Linux system to automatically run a script at startup

Preface Hello everyone, I am Liang Xu. At work, w...

Solve the problem of Navicat for Mysql connection error 1251 (connection failed)

Because what I wrote before was not detailed enou...

MySql index detailed introduction and correct use method

MySql index detailed introduction and correct use...

How to use nodejs to write a data table entity class generation tool for C#

Although Microsoft provides T4 templates, I find ...

Implementation of setting fixed IP when starting docker container

Network type after docker installation [root@insu...

Simple web page code used in NetEase blog

How to use the code in NetEase Blog: First log in...

A brief analysis of the differences between undo, redo and binlog in MySQL

Table of contents Preface 【undo log】 【redo log】 【...

Build Maven projects faster in Docker

Table of contents I. Overview 2. Conventional mul...

Graphical explanation of the solutions for front-end processing of small icons

Preface Before starting this article, let’s do a ...

JavaScript canvas to achieve colorful clock effect

Use canvas to write a colorful clock! 1. Title (1...