ubuntu下在docker中安装mysql5.6 的方法
作者:VAL宋 时间:2024-01-23 08:35:30
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是密码
以上所述是小编给大家介绍的ubuntu下在docker中安装mysql5.6 的方法,希望对大家有所帮助,如果大家有任何疑问欢迎各我留言,小编会及时回复大家的!
来源:http://blog.csdn.net/valsong/article/details/72599434
标签:ubuntu,docker,mysql5.6
0
投稿
猜你喜欢
JavaScript框架比较:DOM遍历
2010-04-23 14:41:00
Notice: Undefined index: page in E:\\PHP\\test.php on line 14
2023-10-27 20:04:46
在网页设计中,如何使用图标来支持内容?[译]
2009-03-16 16:35:00
MAC下Anaconda+Pyspark安装配置详细步骤
2021-02-11 18:15:51
Python的词法分析与语法分析
2022-06-20 13:58:34
百度百科的图片轮播代码
2009-05-06 12:58:00
python飞机大战pygame游戏背景设计详解
2022-01-09 00:20:37
Python实现为图片添加水印的示例详解
2023-11-14 09:49:09
Mysql的服务无法启动的1067错误解决
2012-01-05 19:31:56
Python基础必备之语法结构详解
2023-12-07 05:29:06
Mysql查询时间区间日期列表实例代码
2024-01-17 16:17:32
vue+echarts封装气泡图的方法
2024-05-09 15:09:45
使用Dajngo 通过代码添加xadmin用户和权限(组)
2021-08-07 17:43:59
python 调用pyautogui 实时获取鼠标的位置、移动鼠标的方法
2021-01-03 05:25:29
python中opencv 直方图处理
2021-12-24 09:45:17
Python中异常捕获与处理的方法总结
2023-12-10 07:48:24
Flask处理Web表单的实现方法
2021-10-20 17:13:36
加密处理使密码更安全[CFS编码加密]
2008-03-19 13:30:00
numpy之sum()的使用及说明
2023-12-12 00:31:16
Python + selenium + crontab实现每日定时自动打卡功能
2021-06-10 19:45:42