旗下导航:搜·么
当前位置:网站首页 > MySQL教程 > 正文

ubuntu下在docker中装置mysql5.6实例详解【MySQL教程】,mysql5.6,ubuntu,docker

作者:搜教程发布时间:2019-12-01分类:MySQL教程浏览:81评论:0


导读:本文重要引见了ubuntu下在docker中装置mysql5.6的要领,须要的朋侪能够参考下,希望能协助到人人。1.装置mysql5.6dockerrunm...
本文重要引见了ubuntu下在docker中装置mysql5.6 的要领,须要的朋侪能够参考下,希望能协助到人人。

1.装置mysql5.6


docker run mysql:5.6

等一切项目都是Download complet 装置终了


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

2.运用当地账号建立一个文件夹用来映照docker中mysql的设置文件

个中继承建立conf、data、logs 3个文件夹

我的设置以下


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

3.建立mysql容器

切换到root账号进入到适才建立的mysql1文件夹中


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

建立并启动容器


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

给root设置暗码123456

4.启动mysql容器


docker start mysql11

5.进入mysql的bash


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

个中 env LANG=C.UTF-8 bash 让docker命令行支撑中文

6.复制设置文件


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

7.登录mysql


mysql -u root -p

输入暗码进入

8.检察mysql编码


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)

发明不是utf-8编码

9.修正mysql编码

退出mysql,退出docker


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

修正my.cnf设置文件


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

按i进入编辑形式

到场


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

10.重启docker的mysql再次检察编码


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.建立数据库


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

12.建立用户并受权


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)

%示意恣意IP(能够指定IP)、val是用户名、123456是暗码

相干引荐:

零起步构建一个基于Docker的Laravel运用

怎样运用Docker布置PHP开辟环境

docker装置mysql的简朴实例

以上就是ubuntu下在docker中装置mysql5.6实例详解的细致内容,更多请关注ki4网别的相干文章!

标签:mysql5.6ubuntudocker


欢迎 发表评论: