主頁(yè) > 知識(shí)庫(kù) > ubuntu下在docker中安裝mysql5.6 的方法

ubuntu下在docker中安裝mysql5.6 的方法

熱門標(biāo)簽:成都優(yōu)派外呼系統(tǒng) 沈陽(yáng)電銷外呼系統(tǒng)原理是什么 聊城智能外呼系統(tǒng)運(yùn)營(yíng)商 上海智能外呼系統(tǒng)代理商 電子地圖標(biāo)注電話 寧波企業(yè)外呼系統(tǒng)收費(fèi) 扎樣申請(qǐng)400電話 ps制作地圖標(biāo)注gif 地圖標(biāo)注人員兼職

1.安裝mysql5.6

docker run mysql:5.6

等所有項(xiàng)目都是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.使用本地賬號(hào)創(chuàng)建一個(gè)文件夾用來映射docker中mysql的配置文件

其中繼續(xù)創(chuàng)建conf、data、logs 3個(gè)文件夾

我的配置如下

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

3.創(chuàng)建mysql容器

切換到root賬號(hào)進(jìn)入到剛才創(chuàng)建的mysql1文件夾中

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

創(chuàng)建并啟動(dòng)容器

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設(shè)置密碼123456

4.啟動(dòng)mysql容器

docker start mysql11

5.進(jìn)入mysql的bash

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

其中 env LANG=C.UTF-8 bash 讓docker命令行支持中文

6.復(fù)制配置文件

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

7.登錄mysql

mysql -u root -p

輸入密碼進(jìn)入

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)

發(fā)現(xiàn)不是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進(jìn)入編輯模式

加入

[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.創(chuàng)建數(shù)據(jù)庫(kù)

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

12.創(chuàng)建用戶并授權(quán)

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 的方法,希望對(duì)大家有所幫助,如果大家有任何疑問歡迎各我留言,小編會(huì)及時(shí)回復(fù)大家的!

您可能感興趣的文章:
  • 在docker上安裝運(yùn)行mysql實(shí)例
  • Docker安裝MySQL8的方法步驟
  • Docker安裝MySQL8.0的實(shí)現(xiàn)方法
  • docker上安裝使用mysql鏡像
  • Docker 安裝 MySQL(8和5.7)
  • 在docker中安裝mysql詳解
  • docker下mysql 8.0.20 安裝配置方法圖文教程
  • Docker安裝常用組件(mysql,redis)的方法
  • Docker同時(shí)安裝MySQL和MariaDB的方法步驟
  • linux下利用Docker安裝mysql的步驟

標(biāo)簽:咸寧 內(nèi)江 AXB 三明 汕頭 朔州 宿州 林芝

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《ubuntu下在docker中安裝mysql5.6 的方法》,本文關(guān)鍵詞  ubuntu,下在,docker,中,安裝,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《ubuntu下在docker中安裝mysql5.6 的方法》相關(guān)的同類信息!
  • 本頁(yè)收集關(guān)于ubuntu下在docker中安裝mysql5.6 的方法的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章