33.Docker安装Mysql及用户配置

<div class="forFlow">
    <div id="post_detail">
<!--done--> <div id="topics"> <div class="post"> <h1 class="postTitle"> <a id="cb\_post\_title\_url" class="postTitle2" href="https://www.cnblogs.com/wangjunwei/p/11057976.html">33.Docker安装Mysql及用户配置</a> </h1> <div class="clear"></div> <div class="postBody"> <div id="cnblogs\_post\_body" class="blogpost-body"><p>mysql在官方上有两个镜像<br> <img id="img1560954098329" src="https://img2018.cnblogs.com/other/87548/201906/87548-20190620121450771-1333171222.png" alt=""><br> 这个是一个优化过的mysql<br> <img id="img1560954118116" src="https://img2018.cnblogs.com/other/87548/201906/87548-20190620121450796-15985861.png" alt=""><br> 使用这个命令<br> <img id="img1560954225829" src="https://img2018.cnblogs.com/other/87548/201906/87548-20190620121450826-971016467.png" alt=""><br> 安装mysql<br> <img id="img1560954449385" src="https://img2018.cnblogs.com/other/87548/201906/87548-20190620121450857-35428856.png" alt=""><br> <br> 演示最简单的方式去安装mysql:<br> 这种方式安装的用户名没有,密码没有<br> <img id="img1560954410137" src="https://img2018.cnblogs.com/other/87548/201906/87548-20190620121450879-2057703729.png" alt=""><br> docker run -d -p 3306:3306 --name mysql01 mysql/mysql-server :如果本身没有安装过mysql的镜像的话会自动去下载这个镜像<br> docker ps:看到mysql01正在运行<br> <img id="img1560954537930" src="https://img2018.cnblogs.com/other/87548/201906/87548-20190620121451006-521824836.png" alt=""><br> 我们用客户端去连接测试一下<br> <img id="img1560954668069" src="https://img2018.cnblogs.com/other/87548/201906/87548-20190620121451036-1471010644.png" alt=""><br> 连接不上去的原因呢是因为我们没有在mysql上加用户,加配置<br> docekr log mysql01打印出来。root的默认的密码<br> <img id="img1560954741951" src="https://img2018.cnblogs.com/other/87548/201906/87548-20190620121451095-1455242659.png" alt=""><br> 我们要登陆进去把mysql的密码改了<br> docker exec -it mysql01 bash:进入到mysql的控制台相当于<br> <img id="img1560954813051" src="https://img2018.cnblogs.com/other/87548/201906/87548-20190620121451098-1552060887.png" alt=""><br> ls命令。显示它是一个linux的环境<br> <img id="img1560954842841" src="https://img2018.cnblogs.com/other/87548/201906/87548-20190620121451131-587169098.png" alt=""><br> 然后使用mysql的命令:mysql -uroot -p<br> 然后显示需要输入密码<br> <img id="img1560954888993" src="https://img2018.cnblogs.com/other/87548/201906/87548-20190620121451151-1809545218.png" alt=""><br> use mysql:这个时候就提示必须要修改密码<br> <img id="img1560954980550" src="https://img2018.cnblogs.com/other/87548/201906/87548-20190620121451220-1567358108.png" alt=""><br> mysql 修改密码的语句<br> <img id="img1560955031606" src="https://img2018.cnblogs.com/other/87548/201906/87548-20190620121451231-1033655070.png" alt=""><br> <br> <img id="img1560955063552" src="https://img2018.cnblogs.com/other/87548/201906/87548-20190620121451259-1474222501.png" alt=""><br> use mysql:使用mysql<br> select user,host from user:查询user表的数据。<br> <img id="img1560955090083" src="https://img2018.cnblogs.com/other/87548/201906/87548-20190620121451294-1479930238.png" alt=""><br> 最后都有一个分号<br> <img id="img1560955140211" src="https://img2018.cnblogs.com/other/87548/201906/87548-20190620121451321-541956656.png" alt=""><br> 新建一个自己的账号<br> <img id="img1560955167540" src="https://img2018.cnblogs.com/other/87548/201906/87548-20190620121451361-1067835527.png" alt=""><br> jesse这个用户的host是百分号,所以在任意地方都可以访问<br> <img id="img1560955216495" src="https://img2018.cnblogs.com/other/87548/201906/87548-20190620121451408-1452575726.png" alt=""><br> 使用jesse这个用户测试连接<br> <img id="img1560955249620" src="https://img2018.cnblogs.com/other/87548/201906/87548-20190620121451423-1790812587.png" alt=""><br> <br> <img id="img1560955269770" src="https://img2018.cnblogs.com/other/87548/201906/87548-20190620121451450-1352295187.png" alt=""><br> <br> 字符集的问题<br> 后面会使用ef core来创建mysql 数据库。如果没有默认的字符集的话。创建数据库会出现乱码的情况。我们需要把mysql的默认设置改一下<br> 。默认使用utf-8的字符集<br> show variables like '%char%':<br> <img id="img1560955429200" src="https://img2018.cnblogs.com/other/87548/201906/87548-20190620121451475-1421106914.png" alt=""><br> exit:退出mysql<br> <img id="img1560955476774" src="https://img2018.cnblogs.com/other/87548/201906/87548-20190620121451496-760576858.png" alt=""><br> <br> cd /etc:进入etc的文件夹<br> <img id="img1560955498617" src="https://img2018.cnblogs.com/other/87548/201906/87548-20190620121451554-1895060290.png" alt=""><br> 默认写到这个文件里面 my.cnf<br> <img id="img1560955560100" src="https://img2018.cnblogs.com/other/87548/201906/87548-20190620121451595-548152777.png" alt=""><br> cat my.cnf<br> <img id="img1560955586572" src="https://img2018.cnblogs.com/other/87548/201906/87548-20190620121451647-520220088.png" alt=""><br> 有一个mysqld的东西<br> <img id="img1560955609795" src="https://img2018.cnblogs.com/other/87548/201906/87548-20190620121451691-1193973293.png" alt=""><br> 用vi去编辑。默认没有编辑器 需要去安装<br> yum install vim<br> <img id="img1560955670531" src="https://img2018.cnblogs.com/other/87548/201906/87548-20190620121451693-2118085018.png" alt=""><br> 然后就开始安装vim编辑器了<br> <img id="img1560955725258" src="https://img2018.cnblogs.com/other/87548/201906/87548-20190620121451713-247202623.png" alt=""><br> 需要输入确认<br> <img id="img1560955815121" src="https://img2018.cnblogs.com/other/87548/201906/87548-20190620121451739-1348453701.png" alt=""><br> 安装后运行vim这个命令就可以了。进入一个命令窗口,然后点击q强制退出<br> <img id="img1560955862055" src="https://img2018.cnblogs.com/other/87548/201906/87548-20190620121451764-1323170889.png" alt=""><br> 点击q进行强制退出<br> <img id="img1560955870470" src="https://img2018.cnblogs.com/other/87548/201906/87548-20190620121451787-1159499336.png" alt=""><br> 先ls列出来所有的文件<br> cd /etc:进入etc的文件夹<br> <img id="img1560955962537" src="https://img2018.cnblogs.com/other/87548/201906/87548-20190620121451915-274626407.png" alt=""><br> vim my.cnf:编辑这个文件<br> 在这里输入i 可以进行修改<br> <img id="img1560956056408" src="https://img2018.cnblogs.com/other/87548/201906/87548-20190620121451939-904136012.png" alt=""><br> 这三个命令复制进去<br> <img id="img1560956083246" src="https://img2018.cnblogs.com/other/87548/201906/87548-20190620121451942-659321799.png" alt=""><br> <br> <img id="img1560956115806" src="https://img2018.cnblogs.com/other/87548/201906/87548-20190620121451978-1550508737.png" alt=""><br> 先按esc。然后shift+冒号 按住<br> 出现下面的冒号,输入wq 保存并退出<br> <img id="img1560956170525" src="https://img2018.cnblogs.com/other/87548/201906/87548-20190620121451980-1510844548.png" alt=""><br> 然后用 cat my.cnf看一下修改后的文件<br> <img id="img1560956227305" src="https://img2018.cnblogs.com/other/87548/201906/87548-20190620121452046-244342541.png" alt=""><br> 两种方式,一种是在机器内对mysql进行重启<br> 可以在容器内重启mysql ,但是一旦我们的配置错误,就会导致进不来这个容器了。就像下图这种<br> <img id="img1560956445827" src="https://img2018.cnblogs.com/other/87548/201906/87548-20190620121452049-548097276.png" alt=""><br> 后期会把配置文件挂载到外部,<br> <br> <br> <br> &nbsp;</p><br><hr><pre>如果您觉得阅读本文对您有帮助,请点一下“<b>推荐</b>”按钮,您的<b>“推荐”</b>将是我最大的写作动力!欢迎各位转载,但是未经作者本人同意,转载文章之后<b>必须在文章页面明显位置给出作者和原文连接</b>,否则保留追究法律责任的权利。</pre></div><div id="MySignature"></div> <div class="clear"></div> <div id="blog\_post\_info\_block"> <div id="BlogPostCategory"></div> <div id="EntryTag">标签: <a href="https://www.cnblogs.com/wangjunwei/tag/ASP.NET%20Core%E5%88%86%E5%B8%83%E5%BC%8F%E9%A1%B9%E7%9B%AE%E5%AE%9E%E6%88%98/">ASP.NET Core分布式项目实战</a></div> <div id="blog\_post\_info"><div id="green\_channel"> <a href="javascript:void(0);" id="green\_channel\_digg" onclick="DiggIt(11057976,cb\_blogId,1);green\_channel\_success(this,'谢谢推荐!');">好文要顶</a> <a id="green\_channel\_follow" href="javascript:void(0);">已关注</a> <a id="green\_channel\_favorite" onclick="AddToWz(cb\_entryId);return false;" href="javascript:void(0);">收藏该文</a> <a id="green\_channel\_weibo" href="javascript:void(0);" title="分享至新浪微博" onclick="ShareToTsina()"><img src="https://my.oschina.net//common.cnblogs.com/images/icon\_weibo\_24.png" alt=""></a> <a id="green\_channel\_wechat" href="javascript:void(0);" title="分享至微信" onclick="shareOnWechat()"><img src="https://my.oschina.net//common.cnblogs.com/images/wechat.png" alt=""></a> </div> <div id="author\_profile"> <div id="author\_profile\_info" class="author\_profile\_info"> <a href="https://home.cnblogs.com/u/wangjunwei/" target="\_blank"><img src="https://my.oschina.net//pic.cnblogs.com/face/u87548.jpg?id=03231322" class="author\_avatar" alt=""></a> <div id="author\_profile\_detail" class="author\_profile\_info"> <a href="https://home.cnblogs.com/u/wangjunwei/">GASA</a><br> <a href="https://home.cnblogs.com/u/wangjunwei/followees">关注 - 5</a><br> <a href="https://home.cnblogs.com/u/wangjunwei/followers">粉丝 - 43</a> </div> </div> <div class="clear"></div> <div id="author\_profile\_honor"></div> <div id="author\_profile\_follow"> 我在关注他 <a href="javascript:void(0);" onclick="unfollow('29a68de3-869e-de11-ba8f-001cf0cd104b');return false;">取消关注</a> </div> </div> <div id="div\_digg"> <div class="diggit" onclick="votePost(11057976,'Digg')"> <span class="diggnum" id="digg\_count">0</span> </div> <div class="buryit" onclick="votePost(11057976,'Bury')"> <span class="burynum" id="bury\_count">0</span> </div> <div class="clear"></div> <div class="diggword" id="digg\_tips"> </div> </div> <script type="text/javascript"> currentDiggType = 0; </script></div> <div class="clear"></div> <div id="post\_next\_prev"><a href="https://www.cnblogs.com/wangjunwei/p/11057975.html" class="p\_n\_p\_prefix">« </a> 上一篇:<a href="https://www.cnblogs.com/wangjunwei/p/11057975.html" title="发布于2019-06-20 12:15">32.Docker安装MongoDb</a><br><a href="https://www.cnblogs.com/wangjunwei/p/11060737.html" class="p\_n\_p\_prefix">» </a> 下一篇:<a href="https://www.cnblogs.com/wangjunwei/p/11060737.html" title="发布于2019-06-20 19:22">34.Docker安装Mysql参数及环境变量使用</a><br></div> </div>
1 </div> 2 <div class="postDesc">posted @ <span id="post-date">2019-06-20 12:16</span> <a href="https://www.cnblogs.com/wangjunwei/">GASA</a> 阅读(<span id="post_view_count">174</span>) 评论(<span id="post_comment_count">0</span>) <a href="https://i.cnblogs.com/EditPosts.aspx?postid=11057976" rel="nofollow">编辑</a> <a href="#" onclick="AddToWz(11057976);return false;">收藏</a></div> 3</div> 4<script type="text/javascript">var allowComments=true,cb_blogId=60752,cb_entryId=11057976,cb_blogApp=currentBlogApp,cb_blogUserGuid='29a68de3-869e-de11-ba8f-001cf0cd104b',cb_entryCreatedDate='2019/6/20 12:16:00';loadViewCount(cb_entryId);var cb_postType=1;var isMarkdown=false;</script>
</div><!--end: topics 文章、评论容器--> </div><a name="!comments"></a><div id="blog-comments-placeholder"></div><script type="text/javascript">var commentManager = new blogCommentManager();commentManager.renderComments(0);</script> <div id="comment\_form" class="commentform"> <a name="commentform"></a> <div id="divCommentShow"><div class="comment\_my\_posted"><img style="vertical-align:middle" src="https://my.oschina.net//static.cnblogs.com/images/icon\_comment.gif"> <a href="http://home.cnblogs.com/u/1586533/"><b>kennard\_owen</b></a>:<blockquote class="bq\_post\_comment">楼主,请问下后面的35后面还有更新么,期待中</blockquote></div></div> <div id="comment\_nav"><span id="span\_refresh\_tips"></span><a href="javascript:void(0);" onclick="return RefreshCommentList();" id="lnk\_RefreshComments" runat="server" clientidmode="Static">刷新评论</a><a href="#" onclick="return RefreshPage();">刷新页面</a><a href="#top">返回顶部</a></div> <div id="comment\_form\_container"><script type="text/javascript" src="https://my.oschina.net//mention.cnblogs.com/bundles/mention.js?id=20160615"></script> <div id="commentform\_title">发表评论</div> <span id="tip\_comment" style="color:Red">感谢您的回复:) 服务器端执行耗时109毫秒</span> <p> 昵称:<input type="text" id="tbCommentAuthor" class="author" disabled="disabled" size="50" value="kennard\_owen"> </p> <div class="commentbox\_main"> <div class="commentbox\_title"> <div class="commentbox\_title\_left">评论内容:</div> <div class="commentbox\_title\_right"> <img id="ubb\_quote" class="comment\_icon" src="https://my.oschina.net//static.cnblogs.com/images/ubb/quote.gif" alt="引用" title="添加引用" onclick="insertUBB('tbCommentBody','quote')"> <img id="ubb\_bold" class="comment\_icon" src="https://my.oschina.net//static.cnblogs.com/images/ubb/b.png" alt="粗体" title="添加粗体" onclick="insertUBB('tbCommentBody','b')"> <img id="ubb\_url" class="comment\_icon" src="https://my.oschina.net//static.cnblogs.com/images/ubb/lk.png" alt="链接" title="添加链接" onclick="insertUbbUrl('tbCommentBody')"> <img id="ubb\_indent" class="comment\_icon" src="https://my.oschina.net//static.cnblogs.com/images/ubb/indent.png" alt="缩进" title="添加首行缩进" onclick="insertIndent('tbCommentBody')"> <img id="ubb\_code" class="comment\_icon" src="https://my.oschina.net//static.cnblogs.com/images/ubb/InsertCode.gif" alt="代码" title="添加代码" onclick="insertUbbCode()"> <img id="ubb\_img" class="comment\_icon" src="https://my.oschina.net//static.cnblogs.com/images/ubb/img.gif" alt="图片" title="上传图片" onclick="OpenImageUploadWindow();"> </div> </div> <div class="clear"></div> <textarea id="tbCommentBody" class="comment\_textarea"></textarea> </div> <p id="commentbox\_opt"> <input id="btn\_comment\_submit" type="button" class="comment\_btn" value="提交评论"> <span id="span\_comment\_canceledit" style="display:none"><a href="javascript:void(0);" onclick="return CancelCommentEdit()">不改了</a></span> <a href="javascript:void(0);" onclick="return logout();">退出</a> <a id="commentbox\_opt\_sub" href="javascript:void(0);" title="订阅后有新评论时会邮件通知您" onclick="commentManager.Subscribe()">订阅评论</a> </p> <div id="tip\_comment2" style="color:Red">感谢您的回复:) 服务器端执行耗时109毫秒</div> <p> \[Ctrl+Enter快捷键提交\] </p> <div style="display:none"> <span id="comment\_edit\_id"></span><span id="span\_parentcomment\_id"></span> <span id="span\_parent\_id"></span> <span id="span\_comment\_replyto"></span> <span id="span\_comment\_posted"></span> </div> </div> <div class="ad\_text\_commentbox" id="ad\_text\_under\_commentbox"></div> <div id="ad\_t2"><a href="http://www.ucancode.com/index.htm" target="\_blank" onclick="ga('send', 'event', 'Link', 'click', 'T2-工控')">【推荐】超50万C++/C#源码: 大型实时仿真组态图形源码</a><br><a href="https://group.cnblogs.com/topic/81899.html" target="\_blank" onclick="ga('send', 'event', 'Link', 'click', 'T2-Dell')">【活动】戴尔助力小企业,商务爆品5折秒,最低低至¥2399</a><br><a href="https://q.cnblogs.com/" target="\_blank" onclick="ga('send', 'event', 'Link', 'click', 'T2-博问')">【推荐】程序员问答平台,解决您开发中遇到的技术难题</a><br></div> <div id="opt\_under\_post"></div> <script async="async" src="https://www.googletagservices.com/tag/js/gpt.js"></script> <script> var googletag = googletag || {}; googletag.cmd = googletag.cmd || \[\]; </script> <script> googletag.cmd.push(function() { googletag.defineSlot('/1090369/C1', \[300, 250\], 'div-gpt-ad-1546353474406-0').addService(googletag.pubads()); googletag.defineSlot('/1090369/C2', \[468, 60\], 'div-gpt-ad-1539008685004-0').addService(googletag.pubads()); googletag.pubads().enableSingleRequest(); googletag.enableServices(); }); </script> <div id="cnblogs\_c1" class="c\_ad\_block"> <div id="div-gpt-ad-1546353474406-0" style="height:250px; width:300px;" data-google-query-id="CKn-quq-4-MCFQJzYAod490D1w"><div id="google\_ads\_iframe\_/1090369/C1\_0\_\_container\_\_" style="border: 0pt none;"><iframe id="google\_ads\_iframe\_/1090369/C1\_0" title="3rd party ad content" name="google\_ads\_iframe\_/1090369/C1\_0" width="300" height="250" scrolling="no" marginwidth="0" marginheight="0" frameborder="0" srcdoc="" style="border: 0px; vertical-align: bottom;" data-google-container-id="1" data-load-complete="true"></iframe></div></div> </div> <div id="under\_post\_news"><div class="recomm-block"><b>相关博文:</b><br>· <a href="https://www.cnblogs.com/soaeon/p/10933726.html" target="\_blank" onclick="clickRecomItmem(10933726)">docker使用记录二:mysql安装与配置</a><br>· <a href="https://www.cnblogs.com/lonelyxmas/p/10584949.html" target="\_blank" onclick="clickRecomItmem(10584949)">Docker之Mysql安装及配置</a><br>· <a href="https://www.cnblogs.com/AnkerZhang/p/8556354.html" target="\_blank" onclick="clickRecomItmem(8556354)">docker,mysql,Navicat</a><br>· <a href="https://www.cnblogs.com/nsky/p/10413136.html" target="\_blank" onclick="clickRecomItmem(10413136)">docker安装myql</a><br>· <a href="https://www.cnblogs.com/anlegou/p/10711489.html" target="\_blank" onclick="clickRecomItmem(10711489)">docker上配置mysql主从复制</a><br></div></div> <div id="cnblogs\_c2" class="c\_ad\_block"> <div id="div-gpt-ad-1539008685004-0" style="height:60px; width:468px;" data-google-query-id="CNjWqeq-4-MCFQJzYAod490D1w"><div id="google\_ads\_iframe\_/1090369/C2\_0\_\_container\_\_" style="border: 0pt none;"><iframe id="google\_ads\_iframe\_/1090369/C2\_0" title="3rd party ad content" name="google\_ads\_iframe\_/1090369/C2\_0" width="468" height="60" scrolling="no" marginwidth="0" marginheight="0" frameborder="0" srcdoc="" style="border: 0px; vertical-align: bottom;" data-google-container-id="2" data-load-complete="true"></iframe></div></div> </div> <div id="under\_post\_kb"><div class="itnews c\_ad\_block"><b>最新新闻</b>:<br> · <a href="https://news.cnblogs.com/n/629115/" target="\_blank">近五年 IBM 多达 10 万名员工被裁,占比 1/3</a><br> · <a href="https://news.cnblogs.com/n/629113/" target="\_blank">韩国已确定被移出日本出口白名单,对韩科技企业造成冲击已成定局</a><br> · <a href="https://news.cnblogs.com/n/629112/" target="\_blank">Q1 公有云市场份额:阿里云份额占43%,前四存在变数</a><br> · <a href="https://news.cnblogs.com/n/629111/" target="\_blank">日本正式向运营商发放5G商用牌照</a><br> · <a href="https://news.cnblogs.com/n/629110/" target="\_blank">科学家刚发现一颗长得像足球的行星</a><br>» <a href="http://news.cnblogs.com/" title="IT新闻" target="\_blank">更多新闻...</a></div></div> <div id="HistoryToday" class="c\_ad\_block"></div> <script type="text/javascript"> if(enablePostBottom()) { codeHighlight(); fixPostBody(); setTimeout(function () { incrementViewCount(cb\_entryId); }, 50); deliverT2(); deliverC1(); deliverC2(); loadNewsAndKb(); loadBlogSignature(); LoadPostInfoBlock(cb\_blogId, cb\_entryId, cb\_blogApp, cb\_blogUserGuid); GetPrevNextPost(cb\_entryId, cb\_blogId, cb\_entryCreatedDate, cb\_postType); loadOptUnderPost(); GetHistoryToday(cb\_blogId, cb\_blogApp, cb\_entryCreatedDate); } </script> </div>
</div>
点赞
收藏

评论区

加载中...

相关推荐

MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1

文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s

Oracle 分组与拼接字符串同时使用

SELECTT.,ROWNUMIDFROM(SELECTT.EMPLID,T.NAME,T.BU,T.REALDEPART,T.FORMATDATE,SUM(T.S0)S0,MAX(UPDATETIME)CREATETIME,LISTAGG(TOCHAR(

MySQL部分从库上面因为大量的临时表tmp_table造成慢查询

背景描述Time:20190124T00:08:14.70572408:00User@Host:@Id:Schema:sentrymetaLast_errno:0Killed:0Query_time:0.315758Lock_

手写Java HashMap源码

HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程22

mysql+redis+memcached

<divid"mainContent"<divclass"forFlow"<divid"post\_detail"<!done<divid"topics"<divclass"post"<h1class"postTitle"<aid"cb\_post\_title\_url"class"po

KVM调整cpu和内存

一.修改kvm虚拟机的配置1、virsheditcentos7找到“memory”和“vcpu”标签,将<namecentos7</name<uuid2220a6d1a36a4fbb8523e078b3dfe795</uuid