-
Notifications
You must be signed in to change notification settings - Fork 0
/
local-search.xml
90 lines (43 loc) · 36.7 KB
/
local-search.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<?xml version="1.0" encoding="utf-8"?>
<search>
<entry>
<title>list加法、乘法和赋值</title>
<link href="/2022/10/30/list%E7%9A%84%E5%8A%A0%E6%B3%95%E3%80%81%E4%B9%98%E6%B3%95%E5%92%8C%E8%B5%8B%E5%80%BC/"/>
<url>/2022/10/30/list%E7%9A%84%E5%8A%A0%E6%B3%95%E3%80%81%E4%B9%98%E6%B3%95%E5%92%8C%E8%B5%8B%E5%80%BC/</url>
<content type="html"><![CDATA[<h2 id="正文"><a href="#正文" class="headerlink" title="正文"></a>正文</h2><blockquote><p>这学期做了python语言基础的助教,刚刚在做助教题目,遇到一个list的选择题,一时间我不知道为什么会得到这个选项,于是我从头到尾搞清楚,顺便梳理下相关知识点。</p></blockquote><h3 id="题目如下:"><a href="#题目如下:" class="headerlink" title="题目如下:"></a>题目如下:</h3><p><img src="https://cdn.jsdelivr.net/gh/coder-zc/imagesbed@latest/blog-images/2022/10/31/0f7f0ba232b7fd21db8d5a58431a3bf9-20221031145410-47ed31.png" alt="image-20221030135918353"></p><h3 id="列表的索引和切片"><a href="#列表的索引和切片" class="headerlink" title="列表的索引和切片"></a>列表的索引和切片</h3><blockquote><p>分析1:首先这道题目涉及的知识点是列表的切片(slice)和列表的修改。</p></blockquote><ol><li><p>首先我们明确列表索引和切片返回的值是不一样的,即使是取相同位置的元素。</p><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><code class="hljs python">a = [[<span class="hljs-number">1</span>, <span class="hljs-number">2</span>], [<span class="hljs-number">2</span>, <span class="hljs-number">4</span>], [<span class="hljs-number">3</span>, <span class="hljs-number">6</span>], [<span class="hljs-number">4</span>, <span class="hljs-number">8</span>]]<br><span class="hljs-built_in">print</span>(<span class="hljs-string">f"列表的索引是列表里的1个元素,输出第3个元素:<span class="hljs-subst">{a[<span class="hljs-number">3</span>]}</span>"</span>)<br><span class="hljs-built_in">print</span>(<span class="hljs-string">f"列表的切片是包含该元素的一个列表:<span class="hljs-subst">{a[<span class="hljs-number">3</span>:<span class="hljs-number">4</span>]}</span>"</span>)<br><br>output[<span class="hljs-number">1</span>]:<br>列表的索引是列表里的<span class="hljs-number">1</span>个元素,输出第<span class="hljs-number">3</span>个元素:[<span class="hljs-number">4</span>, <span class="hljs-number">8</span>]<br>列表的切片是包含该元素的一个列表:[[<span class="hljs-number">4</span>, <span class="hljs-number">8</span>]]<br></code></pre></td></tr></table></figure><p>我们看到,虽然<code>a[3]</code>和<code>a[3:4]</code>都是取的列表的第三个元素,但是返回的形式不同。索引理解起来很简单,就是取那个位置的值。而切片是在取那一段范围的值(这里是只取一个值)基础上再加一层列表,即不管里面的元素是什么形式,返回的值都是放在[]里的。</p></li><li><p>二维列表有一点点抽象,我们换成更直观的一维列表来看。</p><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><code class="hljs python">list1 = [i <span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(<span class="hljs-number">10</span>)]<br><span class="hljs-built_in">print</span>(<span class="hljs-string">f"列表的索引是列表的一个元素:<span class="hljs-subst">{list1[<span class="hljs-number">3</span>]}</span>"</span>)<br><span class="hljs-built_in">print</span>(<span class="hljs-string">f"列表的切片是列表的一个列表:<span class="hljs-subst">{list1[<span class="hljs-number">3</span>:<span class="hljs-number">4</span>]}</span>"</span>)<br><br>output[<span class="hljs-number">2</span>]:<br>列表的索引是列表的一个元素:<span class="hljs-number">3</span><br>列表的切片是列表的一个列表:[<span class="hljs-number">3</span>]<br></code></pre></td></tr></table></figure></li></ol><h3 id="列表的赋值和加法"><a href="#列表的赋值和加法" class="headerlink" title="列表的赋值和加法"></a>列表的赋值和加法</h3><blockquote><p>分析2:知识点2,列表赋值给索引列表等价于索引列表(索引列表置为空)+列表,引出列表的加法。理解了列表的加法就明白为什么这里<code>a[3:4]=[10,20]</code>后,a[3]的位置插入两个数10,20。</p></blockquote><ol><li><p>列表的加法</p><p>我们使用列表的加法比较频繁,因为可以很方便的合并列表的元素,可是我们很少去了解为什么列表相加之后会是这个结果呢。在这里我今天来解释一下:</p><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><code class="hljs python">list1 = <span class="hljs-built_in">list</span>(<span class="hljs-built_in">range</span>(<span class="hljs-number">5</span>))<br>list2 = <span class="hljs-built_in">list</span>(<span class="hljs-built_in">range</span>(<span class="hljs-number">6</span>,<span class="hljs-number">10</span>))<br>list3 = list1 + list2<br><span class="hljs-built_in">print</span>(<span class="hljs-string">f"通过列表的加法合并list1和list2:<span class="hljs-subst">{list3}</span>"</span>)<br><br>[output]<span class="hljs-number">3</span>:<br>通过列表的加法合并list1和list2:[<span class="hljs-number">0</span>, <span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>, <span class="hljs-number">6</span>, <span class="hljs-number">7</span>, <span class="hljs-number">8</span>, <span class="hljs-number">9</span>]<br></code></pre></td></tr></table></figure><p>通过上面的代码,我们可以发现加法可以用在合并列表上,但是是如何合并的呢。首先加法对象必须都是列表,然后将加号右边的列表看作一个可迭代的对象,列表里的每个元素逐一的放到加号左边列表的末尾,由此达到合并的效果。这一步操作让我联想到前几天遇到的<strong>list.extend()函数</strong>,它的功能就是将可迭代对象逐一插入到列表末尾(extend()的功能更加强大,它可以支持任何可迭代的对象,比如列表、元组、字符串等。而加法仅仅支持两个列表之间的合并)。与<strong>list.append()</strong> 函数不同(直接将整个元素插入列表的末尾),<strong>关于extend和append函数的区别请看参考1</strong>。</p></li><li><p>上面是和一维列表做加法,体现的还不是很直观,下面将list2换成二维列表,你就可以理解的更加清晰。</p><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><code class="hljs python"><span class="hljs-keyword">import</span> numpy <span class="hljs-keyword">as</span> np<br>list1 = <span class="hljs-built_in">list</span>(<span class="hljs-built_in">range</span>(<span class="hljs-number">5</span>))<br>list2 = np.arange(<span class="hljs-number">10</span>).reshape(<span class="hljs-number">5</span>,<span class="hljs-number">2</span>).tolist()<br>list3 = list1 + list2<br><span class="hljs-built_in">print</span>(<span class="hljs-string">f"输出list2:<span class="hljs-subst">{list2}</span>"</span>)<br><span class="hljs-built_in">print</span>(<span class="hljs-string">f"通过列表的加法合并list1和list2:<span class="hljs-subst">{list3}</span>"</span>)<br><br>[output]<span class="hljs-number">4</span>:<br>输出list2:[[<span class="hljs-number">0</span>, <span class="hljs-number">1</span>], [<span class="hljs-number">2</span>, <span class="hljs-number">3</span>], [<span class="hljs-number">4</span>, <span class="hljs-number">5</span>], [<span class="hljs-number">6</span>, <span class="hljs-number">7</span>], [<span class="hljs-number">8</span>, <span class="hljs-number">9</span>]]<br>通过列表的加法合并list1和list2:[<span class="hljs-number">0</span>, <span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>, [<span class="hljs-number">0</span>, <span class="hljs-number">1</span>], [<span class="hljs-number">2</span>, <span class="hljs-number">3</span>], [<span class="hljs-number">4</span>, <span class="hljs-number">5</span>], [<span class="hljs-number">6</span>, <span class="hljs-number">7</span>], [<span class="hljs-number">8</span>, <span class="hljs-number">9</span>]]<br></code></pre></td></tr></table></figure></li></ol><h3 id="列表的乘法"><a href="#列表的乘法" class="headerlink" title="列表的乘法"></a>列表的乘法</h3><blockquote><p>列表的乘法使用的频率较低,往往在扩充列表时使用。</p></blockquote><ol><li><p>相当于<code>list2=lis1+list1+list1</code>。做了三次加法,归根到底还是加法。</p><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><code class="hljs python">list1 = [i <span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(<span class="hljs-number">3</span>)]<br>list2 = list1*<span class="hljs-number">3</span><br><span class="hljs-built_in">print</span>(<span class="hljs-string">f"输出乘之前的列表list1: <span class="hljs-subst">{list1}</span>"</span>)<br><span class="hljs-built_in">print</span>(<span class="hljs-string">f"输出乘之后的列表list2: <span class="hljs-subst">{list2}</span>"</span>)<br><br>output[<span class="hljs-number">5</span>]:<br>输出乘之前的列表list1: [<span class="hljs-number">0</span>, <span class="hljs-number">1</span>, <span class="hljs-number">2</span>]<br>输出乘之后的列表list2: [<span class="hljs-number">0</span>, <span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">0</span>, <span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">0</span>, <span class="hljs-number">1</span>, <span class="hljs-number">2</span>]<br></code></pre></td></tr></table></figure></li></ol><h3 id="列表的其他运算"><a href="#列表的其他运算" class="headerlink" title="列表的其他运算"></a>列表的其他运算</h3><blockquote><p>列表有减法和除法吗?试一试呢,很明显没有</p></blockquote><ol><li><p>列表的减法</p><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><code class="hljs python">TypeError Traceback (most recent call last)<br>Input In [<span class="hljs-number">103</span>], <span class="hljs-keyword">in</span> <cell line: <span class="hljs-number">3</span>>()<br> <span class="hljs-number">1</span> list1 = <span class="hljs-built_in">list</span>(<span class="hljs-built_in">range</span>(<span class="hljs-number">5</span>))<br> <span class="hljs-number">2</span> list2 = <span class="hljs-built_in">list</span>(<span class="hljs-built_in">range</span>(<span class="hljs-number">6</span>,<span class="hljs-number">10</span>))<br>----> <span class="hljs-number">3</span> list3 = list1 - list2<br> <span class="hljs-number">4</span> <span class="hljs-built_in">print</span>(<span class="hljs-string">f"通过列表的加法合并list1和list2:<span class="hljs-subst">{list3}</span>"</span>)<br><br>TypeError: unsupported operand <span class="hljs-built_in">type</span>(s) <span class="hljs-keyword">for</span> -: <span class="hljs-string">'list'</span> <span class="hljs-keyword">and</span> <span class="hljs-string">'list'</span><br></code></pre></td></tr></table></figure></li><li><p>列表的除法</p><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><code class="hljs python">---------------------------------------------------------------------------<br>TypeError Traceback (most recent call last)<br>Input In [<span class="hljs-number">107</span>], <span class="hljs-keyword">in</span> <cell line: <span class="hljs-number">2</span>>()<br> <span class="hljs-number">1</span> list1 = [i <span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(<span class="hljs-number">3</span>)]<br>----> <span class="hljs-number">2</span> list2 = list1/<span class="hljs-number">3</span><br><br>TypeError: unsupported operand <span class="hljs-built_in">type</span>(s) <span class="hljs-keyword">for</span> /: <span class="hljs-string">'list'</span> <span class="hljs-keyword">and</span> <span class="hljs-string">'int'</span><br><br></code></pre></td></tr></table></figure></li></ol><h2 id="小结"><a href="#小结" class="headerlink" title="小结"></a>小结</h2><ol><li><p>注意列表切片返回值是一个列表</p></li><li><p>列表的加法如何理解,本文重点(ps:列表没有减法和除法)</p></li><li><p>extend和append函数的区别</p></li><li><p>列表(list)和数组(array)的区别,这里篇幅有限,下次再讲!</p></li></ol><h2 id="参考"><a href="#参考" class="headerlink" title="参考"></a>参考</h2><ul><li><p><a href="https://zhuanlan.zhihu.com/p/170580848">list中的append()和extend()方法区别</a></p></li><li><p><a href="https://docs.python.org/zh-cn/3/library/array.html?highlight=extend#array.array.extend">官方文档-extend用法</a></p></li></ul>]]></content>
<categories>
<category>语言</category>
</categories>
<tags>
<tag>python</tag>
<tag>list</tag>
<tag>extend</tag>
</tags>
</entry>
<entry>
<title>Github协作教程</title>
<link href="/2022/09/25/github%E5%8D%8F%E4%BD%9C%E6%8C%87%E5%8D%97/"/>
<url>/2022/09/25/github%E5%8D%8F%E4%BD%9C%E6%8C%87%E5%8D%97/</url>
<content type="html"><![CDATA[<h2 id="环境"><a href="#环境" class="headerlink" title="环境"></a>环境</h2><ul><li><p>windows系统需要安装git</p><ul><li>安装地址:<a href="https://git-scm.com/download/win%EF%BC%8C%E4%B8%80%E8%B7%AFnext%E5%8D%B3%E5%8F%AF%E3%80%82">https://git-scm.com/download/win,一路next即可。</a></li><li>检查是否安装成功:终端输入,git –version,返回版本号即安装成功。</li></ul></li><li><p>macOS\Linux系统自带git无需安装</p></li><li><p>Github官网:<a href="https://github.com/">https://github.com/</a> ,如果没有账号可以注册一个。</p></li><li><p>前端项目仓库地址:<a href="https://github.com/coder-zc/bi-front">https://github.com/coder-zc/bi-front</a></p></li></ul><h2 id="协作步骤"><a href="#协作步骤" class="headerlink" title="协作步骤"></a>协作步骤</h2><h3 id="说明:这里以前端仓库为例,后端仓库也是如此。"><a href="#说明:这里以前端仓库为例,后端仓库也是如此。" class="headerlink" title="说明:这里以前端仓库为例,后端仓库也是如此。"></a>说明:这里以前端仓库为例,后端仓库也是如此。</h3><ol><li><h3 id="在GitHub上Fork项目"><a href="#在GitHub上Fork项目" class="headerlink" title="在GitHub上Fork项目"></a>在GitHub上Fork项目</h3></li></ol><p><img src="https://shuishan.feishu.cn/space/api/box/stream/download/asynccode/?code=YTE3ODg4YmU3MGM1YTg3YjlkZjgwNGE3YTMyMTZmMTJfQUpEaDFrajgxZmRYZTZXczRPR1p4NlRlTE9DVk4zMGhfVG9rZW46Ym94Y242dWxNSGVDd2NlWVB0SVQ0V0dBM21nXzE2NjQxMTU1NjM6MTY2NDExOTE2M19WNA" alt="img"></p><ol><li><h3 id="克隆项目到本地"><a href="#克隆项目到本地" class="headerlink" title="克隆项目到本地"></a>克隆项目到本地</h3></li></ol><p><img src="https://shuishan.feishu.cn/space/api/box/stream/download/asynccode/?code=ZjAxY2ZkNTBkZWQ4NTQwMTMyMjZkMThlNGNiOTgyN2Ffc01XakZzRTV3bzY1NlgyUDJNeFhaWkhvOHhKdDF1TmlfVG9rZW46Ym94Y25MU2l1dU1YWXBpbFlNajlHRFVneVFnXzE2NjQxMTU1NjM6MTY2NDExOTE2M19WNA" alt="img"></p><ul><li>本地进入一个空文件夹,右键点击git bash或者终端。</li></ul><p><img src="https://shuishan.feishu.cn/space/api/box/stream/download/asynccode/?code=NjY0NjJiMjFjM2Y5Y2NmY2NhNzEyYTFhNDdjNmYxNmVfR0tLaEhzMDFxcmhpcXRDbno2VWlHZDY5amRIOVYwVjRfVG9rZW46Ym94Y25SQkhmZ2hpTXhUd0pnU1RYRU5yWkhlXzE2NjQxMTU1NjM6MTY2NDExOTE2M19WNA" alt="img"></p><ul><li>执行git clone命令,地址位你fork后的仓库git地址,每个人的都不一样。可以看到本地出现了bi-front项目文件夹,我们使用VSCode或者WebStorm打开这个文件夹。</li></ul><p><img src="https://shuishan.feishu.cn/space/api/box/stream/download/asynccode/?code=MDUzNDE0YjUzNTMwZjg5NTMyMTljNjk3MzZjYTRjYjJfRDdaQ1Zrdlc4UDhBWEFQNktlS3JLdGZ6eUlVUzNNSjJfVG9rZW46Ym94Y25DbUprRUdXQXphcmJvbW5UVVl1Q0ljXzE2NjQxMTU1NjM6MTY2NDExOTE2M19WNA" alt="img"></p><h3 id="3-新建本地开发分支"><a href="#3-新建本地开发分支" class="headerlink" title="3.新建本地开发分支"></a>3.新建本地开发分支</h3><ol><li>查看远程分支。在IDE中打开终端,输入git remote -v,如图所示,只有一个origin远程分支</li></ol><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs undefined">git remote -v<br></code></pre></td></tr></table></figure><p><img src="https://shuishan.feishu.cn/space/api/box/stream/download/asynccode/?code=MjE3NTZlNDkyMTUwY2I2ODkxM2E1M2ZlNGY5MDZjNmVfb2ZCUGt3eW1Fa3J3Z0NOY0FBRDR0RkVEUUVya1NXQ0ZfVG9rZW46Ym94Y24yTkd3T0JIT21oWlJiOU5sMk9DSjZjXzE2NjQxMTU1NjM6MTY2NDExOTE2M19WNA" alt="img"></p><ol><li>新建开发分支</li></ol><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><code class="hljs undefined"># 查看本地分支,此时本地应该只有master分支<br>git branch<br># 我们不应该在master分支上开发代码,应该新建一个分支在此进行开发;<br># 该命令是新建一个分支并切换到此分支;是git branch和git checkout的组合命令。这里分支名可以随便起,比如我这里的命令是git checkout -b coder-zc,新建一个coder-zc分支。<br>git checkout -b (分支名)<br></code></pre></td></tr></table></figure><ol><li>添加上游仓库</li></ol><ul><li><p>地址:<a href="https://github.com/coder-zc/bi-front.git">https://github.com/coder-zc/bi-front.git</a></p></li><li><p>上游仓库的地址都是一样的,也就是汇聚我们所有人提交的代码的仓库。</p></li></ul><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><code class="hljs Plain">git remote add upstream https://github.com/coder-zc/bi-front.git<br><br># upstream名字也是随便取的,如果写错了,可以执行删除远程分支命令<br>git remote remove 仓库名<br></code></pre></td></tr></table></figure><ul><li>查看我们远程分支,会有两个远程仓库。</li></ul><p><img src="https://shuishan.feishu.cn/space/api/box/stream/download/asynccode/?code=NWEzYjQ5Zjk4MWZjOGE4ZGE4MGM0ZTBlY2ZlNTk2MDJfRjM3NUtIaDJvWHdCeDdSY1RteUtDdE1zR0Rwa3BOaDBfVG9rZW46Ym94Y25hRXBudGFFbVJHaTVPZXRoenpYMEpiXzE2NjQxMTU1NjM6MTY2NDExOTE2M19WNA" alt="img"></p><ul><li>两个远程仓库的说明<ul><li>origin:是我们提交代码的远程仓库,即我们本地的代码会提交到这个远程仓库,也是我们自己的仓库。如何把我们的代码提交到upstream仓库呢,通过发起PullRequest向上游仓库发起合并请求,如果通过,则代码会合入上游仓库。</li><li>upstream:是我们更新代码的仓库,每次提交代码前会从此仓库拉最新的代码,然后再提交。</li></ul></li></ul><h3 id="4-提交代码"><a href="#4-提交代码" class="headerlink" title="4. 提交代码"></a>4. 提交代码</h3><ul><li>在每次提交代码前都向上游仓库同步一下代码,拉取dev分支的代码,master是保护分支。</li></ul><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><code class="hljs Shell">git pull upstream dev<br><span class="hljs-meta prompt_"># </span><span class="language-bash">提交所有修改,你也可以提交部分修改</span><br>git add .<br><span class="hljs-meta prompt_"></span><br><span class="hljs-meta prompt_"># </span><span class="language-bash">引号内容为提交时的注释,为了规范提交,请按照此格式编写,feat/fix/doc/...:描述你做了什么修改,要简练清晰,feat表示你新增的什么功能,fix表示你修改了什么Bug,doc表示文档类的修改,下面是个示例。</span><br>git commit -m "doc:修改README.md"<br><span class="hljs-meta prompt_"></span><br><span class="hljs-meta prompt_"># </span><span class="language-bash">提交代码到origin仓库,这里coder-zc是我的本地分支,你要换成你的分支名</span><br>git push -u origin coder-zc:master<br></code></pre></td></tr></table></figure><h3 id="5-发起Pull-Request合并代码"><a href="#5-发起Pull-Request合并代码" class="headerlink" title="5.发起Pull Request合并代码"></a>5.发起Pull Request合并代码</h3><ul><li><p>此时代码已经提交到master仓库</p></li><li><p>然后我们new 一个PR</p></li></ul><p><img src="https://shuishan.feishu.cn/space/api/box/stream/download/asynccode/?code=YmZmZDgxMmY1ODRlODY1YjhhY2M3ZWU3NDBkMDc1OGFfR01lZzVDMWF3YW1HQnVDR0NLWndCOFdralFCVkpTeHRfVG9rZW46Ym94Y25WbktubDR3SzVHcUpiNk5ERWEwQ3RlXzE2NjQxMTU1NjM6MTY2NDExOTE2M19WNA" alt="img"></p><ul><li>注意分支的选取</li></ul><p><img src="https://shuishan.feishu.cn/space/api/box/stream/download/asynccode/?code=OTdiNDYyOTk3YjgwODA5MzY3M2NkZTFiNjBkNGE1ZWNfVlBCaDROTEpKVjdtY3hnMnpUMmI4UDladXJTdkl3NjhfVG9rZW46Ym94Y25NVmVxTGtNcW5aWmFpV1lHQzBJQUFDXzE2NjQxMTU1NjM6MTY2NDExOTE2M19WNA" alt="img"></p><p>至此,你的PR如果同意合并,你就成功对此项目做出贡献。</p>]]></content>
<categories>
<category>教程</category>
</categories>
<tags>
<tag>git</tag>
<tag>github</tag>
</tags>
</entry>
<entry>
<title>数据库被删了之后怎么办</title>
<link href="/2022/06/06/%E6%95%B0%E6%8D%AE%E5%BA%93%E8%A2%AB%E5%88%A0%E4%BA%86%E4%B9%8B%E5%90%8E%E6%80%8E%E4%B9%88%E5%8A%9E/"/>
<url>/2022/06/06/%E6%95%B0%E6%8D%AE%E5%BA%93%E8%A2%AB%E5%88%A0%E4%BA%86%E4%B9%8B%E5%90%8E%E6%80%8E%E4%B9%88%E5%8A%9E/</url>
<content type="html"><![CDATA[<h3 id="前言"><a href="#前言" class="headerlink" title="前言"></a>前言</h3><p>2022年0531日1:30记录一下,晚上数据中台课上,突然发现自己作业里部署到服务器上docker中的数据库被黑掉了,密码设置为123456不是你黑我数据库的理由啊!TNND,不知道你怎么办到的,0521注册了这个超级管理员,把我的数据库全部给删了,仅仅在docker容器的日志查到这么一点记录。是不是人啊,如果是黑客闲的蛋疼啊!我这一个选修课作业的数据库的数据也没啥价值,当然我也没有给数据库备份,所以就是我又凭着记忆重建了数据库,边弄的时候边问候你这个《小可爱》。吃一堑,长一智,仅此一事,对于数据库的管理我一定要慎重,无论大小。所以一定要做好数据库的备份,以及定期修改密码。</p><p><img src="https://cdn.nlark.com/yuque/0/2022/jpeg/601906/1653932634456-fe729092-7215-4cb6-aa48-2b99ab2e10d5.jpeg" alt="屏幕截图 2022-05-30 190531.jpg"></p><p><img src="https://cdn.nlark.com/yuque/0/2022/jpeg/601906/1653932634486-c9bb27c3-1f44-4175-af97-65e81fecc589.jpeg" alt="屏幕截图 2022-05-30 184920.jpg"></p><h3 id="数据库介绍"><a href="#数据库介绍" class="headerlink" title="数据库介绍"></a>数据库介绍</h3><p>版本:MySQL8.x<br>环境:docker<br>【注】:mysql8.x以后mysql数据库中的user表无password字段,故网上MySQL5.x的教程不适用。</p><h3 id="数据库密码修改"><a href="#数据库密码修改" class="headerlink" title="数据库密码修改"></a>数据库密码修改</h3><h4 id="可以登录数据库"><a href="#可以登录数据库" class="headerlink" title="可以登录数据库"></a>可以登录数据库</h4><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><code class="hljs shell"><span class="hljs-meta prompt_"># </span><span class="language-bash">登录数据库</span><br>mysql -uroot -p密码<br><span class="hljs-meta prompt_"></span><br><span class="hljs-meta prompt_"># </span><span class="language-bash">选中数据库</span><br>use mysql;<br><span class="hljs-meta prompt_"></span><br><span class="hljs-meta prompt_"># </span><span class="language-bash">修改密码</span><br>ALTER USER 'root'@'%' IDENTIFIED BY '新密码' PASSWORD EXPIRE NEVER;<br><span class="hljs-meta prompt_"></span><br><span class="hljs-meta prompt_"># </span><span class="language-bash">修改本地密码</span><br>ALTER USER 'root'@'localhost' IDENTIFIED BY '新密码';<br><br>【注】:两条命令都要执行,一开始我只执行了第二条命令,导致我本地密码修改了,远程密码没有修改,即navicat连接数据库密码没有改变。<br><span class="hljs-meta prompt_"></span><br><span class="hljs-meta prompt_"># </span><span class="language-bash">刷新</span><br>flush privileges;<br></code></pre></td></tr></table></figure><h4 id="无法登录数据库"><a href="#无法登录数据库" class="headerlink" title="无法登录数据库"></a>无法登录数据库</h4><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><code class="hljs shell"><span class="hljs-meta prompt_"># </span><span class="language-bash">对于docker容器这种情况</span><br><span class="hljs-meta prompt_"># </span><span class="language-bash">进入docker终端</span><br>docker exec -it mysql的容器名 /bin/bash<br><span class="hljs-meta prompt_"></span><br><span class="hljs-meta prompt_"># </span><span class="language-bash">进入</span><br>cd /etc/mysql/conf.d/<br><span class="hljs-meta prompt_"></span><br><span class="hljs-meta prompt_"># </span><span class="language-bash">打开docker.cnf文件</span><br>vi docker.cnf<br><span class="hljs-meta prompt_"></span><br><span class="hljs-meta prompt_">#</span><span class="language-bash">加入这行命令,免密登录,直接输入mysql即可登录</span><br>skip-grant-tables<br><br>【注】:docker里第一次安装vim可能失败,需要先执行,然后执行安装vim命令<br>apt-get install update<br>apt-get install vim<br><span class="hljs-meta prompt_"></span><br><span class="hljs-meta prompt_"># </span><span class="language-bash">修改完后需要退出重启docker容器</span><br>进入mysql后参照可以登录数据库的情况修改密码,如果密码无法修改,请将docker.cnf添加的命令行去掉,然后重启docker容器<br></code></pre></td></tr></table></figure><h3 id="数据库备份与恢复"><a href="#数据库备份与恢复" class="headerlink" title="数据库备份与恢复"></a>数据库备份与恢复</h3><p>备份方法:</p><ul><li>mysqldump,可百度了解,mysql自带的备份工具;</li><li>第三方软件:如Navicat的备份</li></ul><h4 id="mysqldump"><a href="#mysqldump" class="headerlink" title="mysqldump"></a>mysqldump</h4><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><code class="hljs shell"><span class="hljs-meta prompt_"># </span><span class="language-bash">备份cpu数据库</span><br>mysqldump -uroot -pdaseDMP cpu > cpu_0531.sql<br><span class="hljs-meta prompt_"></span><br><span class="hljs-meta prompt_"># </span><span class="language-bash">压缩备份java</span><br>mysqldump -uroot -pdaseDMP java | gzip > java_0531.sql.gz<br><span class="hljs-meta prompt_"></span><br><span class="hljs-meta prompt_"># </span><span class="language-bash">备份power</span><br>mysqldump -uroot -pdaseDMP power > power_0531.sql<br><span class="hljs-meta prompt_"></span><br><span class="hljs-meta prompt_"># </span><span class="language-bash">备份power的一张表</span><br>mysqldump -p power power_ssj2008 > power_power_ssj2008_0531.txt <br><span class="hljs-meta prompt_"></span><br><span class="hljs-meta prompt_"># </span><span class="language-bash">备份power表中的一部分</span><br>mysqldump -p -where="Result BETWEEN 20900 AND 30000" power power_ssj2008 > power_power_ssj2008_part_0531.txt <br><br></code></pre></td></tr></table></figure><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><code class="hljs shell"><span class="hljs-meta prompt_"># </span><span class="language-bash">恢复cpu</span><br>mysql -uroot -pdaseDMP cpu < cpu_0531.sql<br><span class="hljs-meta prompt_"></span><br><span class="hljs-meta prompt_"># </span><span class="language-bash">恢复java</span><br>gzip -d < java_0531.sql.gz | mysql -uroot -pdaseDMP java<br><span class="hljs-meta prompt_"></span><br><span class="hljs-meta prompt_"># </span><span class="language-bash">恢复power</span><br>mysql -uroot -pdaseDMP power < power_0531.sql<br></code></pre></td></tr></table></figure><h4 id="Navicat"><a href="#Navicat" class="headerlink" title="Navicat"></a>Navicat</h4><p>连接数据库,右键备份选择新建备份。<br><img src="https://cdn.nlark.com/yuque/0/2022/png/601906/1653933524571-f3936a81-5f8d-4fce-bb2b-6475a065f27f.png" alt="image.png"></p><h3 id="创建新用户"><a href="#创建新用户" class="headerlink" title="创建新用户"></a>创建新用户</h3><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><code class="hljs sql"># 创建一个新用户user1,密码为<span class="hljs-number">123456</span>,只能在本机登录<br><span class="hljs-keyword">create</span> <span class="hljs-keyword">user</span> <span class="hljs-string">'user1'</span>@<span class="hljs-string">'localhost'</span> identified <span class="hljs-keyword">by</span> <span class="hljs-string">'123456'</span><br><br># 创建一个新用户user1,密码为<span class="hljs-number">123456</span>,只能在任意机器登录<br><span class="hljs-keyword">create</span> <span class="hljs-keyword">user</span> <span class="hljs-string">'user1'</span>@<span class="hljs-string">'%'</span> identified <span class="hljs-keyword">by</span> <span class="hljs-string">'123456'</span><br><br><br># 授权<br><span class="hljs-keyword">grant</span> <span class="hljs-keyword">all</span> privileges <span class="hljs-keyword">on</span> 数据库 <span class="hljs-keyword">to</span> <span class="hljs-string">'用户名'</span>@<span class="hljs-string">'ip地址'</span><br><br># 撤销授权<br><span class="hljs-keyword">revoke</span> <span class="hljs-keyword">all</span> privilleges <span class="hljs-keyword">from</span> 数据库 <span class="hljs-keyword">to</span> <span class="hljs-string">'用户名'</span>@<span class="hljs-string">'ip地址'</span><br><br></code></pre></td></tr></table></figure><h3 id="中台数据库备份"><a href="#中台数据库备份" class="headerlink" title="中台数据库备份"></a>中台数据库备份</h3><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><code class="hljs shell">mysqldump -uroot -p1227apple dataMidStage > dataMidStage_0916_bk.sql<br><span class="hljs-meta prompt_"># </span><span class="language-bash">将docker文件复制到宿主机</span><br>docker cp mariadb:/dataMidStage_0916_bk.sql /home/coder-zc/dataMidStage/db_backup<br><span class="hljs-meta prompt_"># </span><span class="language-bash">将备份文件下载到本地电脑</span><br>scp -r root@47.102.204.29:/home/coder-zc/dataMidStage/db_backup/dataMidStage_0916_bk.sql ./<br></code></pre></td></tr></table></figure>]]></content>
<categories>
<category>数据库</category>
</categories>
<tags>
<tag>MySQL</tag>
<tag>备份</tag>
</tags>
</entry>
</search>