ubuntu下在docker中安装mysql5.6 的方法
1.安装mysql5.6
dockerrunmysql:5.6
等所有项目都是Downloadcomplet安装完毕
5.6:Pullingfromlibrary/mysql 10a267c67f42:Pullcomplete c2dcc7bb2a88:Pullcomplete 17e7a0445698:Pullcomplete 9a61839a176f:Pullcomplete d4657fda01d9:Pullcomplete c5278a445e5d:Pullcomplete 197c0b76f238:Pullcomplete f54c5432bac4:Pullcomplete c26b15abee8a:Pullcomplete 80dbe6022c18:Pullcomplete 435678c09612:Pullcomplete Digest:sha256:84372107beb1de34bd4673049ea61bc35f374a2b4f19fd5a3abd4d0a2a50b715 Status:Downloadednewerimageformysql:5.6 error:databaseisuninitializedandpasswordoptionisnotspecified YouneedtospecifyoneofMYSQL_ROOT_PASSWORD,MYSQL_ALLOW_EMPTY_PASSWORDandMYSQL_RANDOM_ROOT_PASSWORD
2.使用本地账号创建一个文件夹用来映射docker中mysql的配置文件
其中继续创建conf、data、logs3个文件夹
我的配置如下
val@val-linux:~/docker/mysql1$pwd /home/val/docker/mysql1 val@val-linux:~/docker/mysql1$ls confdatalogs
3.创建mysql容器
切换到root账号进入到刚才创建的mysql1文件夹中
root@val-linux:/home/val#cd/home/val/docker/mysql1/ root@val-linux:/home/val/docker/mysql1#
创建并启动容器
dockerrun-p33061:3306--namemysql1-v$PWD/conf:/etc/mysql-v$PWD/logs:/logs-v$PWD/data:/mysql_data-eMYSQL_ROOT_PASSWORD=123456-dmysql: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容器
dockerstartmysql11
5.进入mysql的bash
dockerexec-itmysql1envLANG=C.UTF-8bash
其中envLANG=C.UTF-8bash让docker命令行支持中文
6.复制配置文件
cp/usr/my.cnf/etc/mysql/my.cnf
7.登录mysql
mysql-uroot-p
输入密码进入
8.查看mysql编码
mysql>showvariableslike'%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/| +--------------------------+----------------------------+ 8rowsinset(0.01sec)
发现不是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#vimconf/my.cnf
按i进入编辑模式
加入
[client]default-character-set=utf8 [mysql]default-character-set=utf8 [mysqld]character-set-server=utf81 esc:wq!保存退出
10.重启docker的mysql再次查看编码
root@val-linux:/home/val/docker/mysql1#dockerstopmysql1 mysql1 root@val-linux:/home/val/docker/mysql1#dockerstartmysql1 mysql1 root@val-linux:/home/val/docker/mysql1#dockerexec-itmysql1envLANG=C.UTF-8bash root@8b83a30acbf8:/#mysql-uroot-p Enterpassword: WelcometotheMySQLmonitor.Commandsendwith;or\g. YourMySQLconnectionidis1 Serverversion:5.6.36MySQLCommunityServer(GPL) Copyright(c)2000,2017,Oracleand/oritsaffiliates.Allrightsreserved. OracleisaregisteredtrademarkofOracleCorporationand/orits affiliates.Othernamesmaybetrademarksoftheirrespective owners. Type'help;'or'\h'forhelp.Type'\c'toclearthecurrentinputstatement. mysql>showvariableslike'%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/| +--------------------------+----------------------------+ 8rowsinset(0.00sec)
11.创建数据库
mysql>createdatabaserise; QueryOK,1rowaffected(0.00sec) mysql>userise; Databasechanged
12.创建用户并授权
mysql>grantallprivilegesonrise.*toval@'%'identifiedby'123456'; QueryOK,0rowsaffected(0.00sec) mysql>flushprivileges; QueryOK,0rowsaffected(0.00sec)
%表示任意IP(可以指定IP)、val是用户名、123456是密码
以上所述是小编给大家介绍的ubuntu下在docker中安装mysql5.6的方法,希望对大家有所帮助,如果大家有任何疑问欢迎各我留言,小编会及时回复大家的!