Home > Database > Mysql Tutorial > body text

Detailed explanation of how to install mysql5.6 in docker under ubuntu

黄舟
Release: 2017-05-28 09:47:16
Original
1411 people have browsed it

This article mainly introduces the method of installing mysql5.6 in docker under ubuntu. Friends who need it can refer to it

1. Install mysql5.6

docker run mysql:5.6
Copy after login

Wait for all projects to be Download complet and the installation is complete

5.6: Pulling from library/mysql
10a267c67f42: Pull complete 
c2dcc7bb2a88: Pull complete 
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
Copy after login

2. Use a local account to create a folder for mapping Configuration file of mysql 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
Copy after login

3. Create 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#
Copy after login

Create and start the 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
用本地33061端口映射docker的3306端口 
给容器命名mysql1 
用本地/home/val/docker/mysql1/conf映射mysql的conf 
用本地/home/val/docker/mysql1/logs映射mysql的logs 
用本地/home/val/docker/mysql1/data映射mysql的mysql_data
Copy after login

Give root Set the password 123456

4. Start the mysql container

docker start mysql11
Copy after login

5. Enter the mysql bash

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

where 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
Copy after login

7. Log in to mysql

mysql -u root -p
Copy after login

Enter the password

8. Check the 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)
Copy after login

and find that it is not utf-8 encoding

9. Modify the mysql encoding

Exitmysql, exit docker

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

Modify my.cnf configuration file

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

Press i to enter

edit mode

Join

[client] default-character-set=utf8 
[mysql] default-character-set=utf8 
[mysqld] character-set-server=utf8 1
esc :wq! 保存退出
Copy after login

10. Restart docker’s mysql and check the encoding 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)
Copy after login

11.Create database

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

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)
Copy after login

% represents any IP (IP can be specified), val is the user name, and 123456 is the password

The above is the detailed content of Detailed explanation of how to install mysql5.6 in docker under ubuntu. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template