Centos6.8通过yum安装mysql5.7

<p>1.安装mysql的yum源</p><p>a.下载配置mysql的yum源的rpm包</p><p><img src="/up_pic/201901/100328091213.png" title="100328091213.png"/></p><p><img src="/up_pic/201901/100328098655.png" title="100328098655.png"/></p><p><img src="/up_pic/201901/100328098334.png" title="100328098334.png"/></p><p></p><p></p><p></p><p>根据上面3张图片中的操作下载下来的rpm文件可以通过如下命令获取:</p><p>wget https://dev.mysql.com/get/mysql57-community-release-el6-9.noarch.rpm</p><p></p><p>b.安装用来配置mysql的yum源的rpm包</p><p>rpm -Uvh mysql57-community-release-el6-9.noarch.rpm</p><p>或</p><p>yum localinstall -y mysql57-community-release-el6-9.noarch.rpm </p><p>安装成功后在/etc/yum.repos.d/下会多出几个mysql的yum源的配置,如下:</p><p><img src="/up_pic/201901/100328386229.png" title="100328386229.png" alt="4.png"/></p><p></p><p>2.安装mysql</p><p>yum install mysql-community-server</p><p></p><p>3.开启mysql服务</p><p>service mysqld start</p><p><img src="/up_pic/201901/100329069135.png" title="100329069135.png" alt="5.png"/></p><p></p><p>mysql安装成功后创建的超级用户&#39;root&#39;@&#39;localhost&#39;的密码会被存储在/var/log/mysqld.log,可以使用如下命令查看密码</p><p>grep &#39;temporary password&#39; /var/log/mysqld.log</p><p><img src="/up_pic/201901/100329265126.png" title="100329265126.png" alt="6.png"/></p><p></p><p>使用mysql生成的&#39;root&#39;@&#39;localhost&#39;用户和密码登录数据库,并修改 其密码,具体命令</p><p>shell&gt; mysql -uroot -p</p><p><img src="/up_pic/201901/100329534629.png" title="100329534629.png" alt="7.png"/></p><p>mysql&gt; ALTER USER &#39;root&#39;@&#39;localhost&#39; IDENTIFIED BY &#39;MyNewPass4!&#39;;</p><p><img src="/up_pic/201901/100330223706.png" title="100330223706.png" alt="8.png"/></p><p></p><p>4.开启远程连接</p><p>设置iptables开放3306端口</p><p>vi /etc/sysconfig/iptables</p><p><img src="/up_pic/201901/100330387698.png" title="100330387698.png" alt="9.png"/></p><p></p><p>如果此时使用telnet远程登录mysql服务会出错:</p><p><img src="/up_pic/201901/100330466268.png" title="100330466268.png" alt="10.png"/></p><p></p><p>解决此问题的方法为:</p><p>将localhost改成%</p><p>进入mysql的BIN目录</p><p>代码如下<span class="Apple-tab-span" ></span></p><p>mysql -u root -p</p><p>mysql&gt;use mysql;</p><p>mysql&gt;update user set host =&#39;%&#39;where user =&#39;root&#39;;</p><p>mysql&gt;flush privileges;</p><p></p><p>具体分析</p><p>1、在本机登入mysql后,更改&quot;mysql&quot;数据库里的&quot;user&quot;表里的&quot;host&quot;项,从&quot;localhost&quot;改为&#39;%&#39;。</p><p>代码如下<span class="Apple-tab-span" ></span></p><p>mysql&gt;</p><p>mysql&gt;use mysql;</p><p>mysql&gt;select &#39;host&#39; from user where user=&#39;root&#39;; </p><p></p><p> #查看mysql库中的user表的host值(即可进行连接访问的主机/IP名称)</p><p></p><p></p><p>代码如下<span class="Apple-tab-span" ></span></p><p>mysql&gt;update user set host = &#39;%&#39; where user =&#39;root&#39;;</p><p>#修改host值(以通配符%的内容增加主机/IP地址,当然也可以直接增加某个特定IP地址,如果执行update语句时出现ERROR 1062 (23000): Duplicate entry &#39;%-root&#39; for key &#39;PRIMARY&#39; 错误,需要select host from user where user = &#39;root&#39;;</p><p>查看一下host是否已经有了%这个值,如果有了直接执行下面的flush privileges;即可)</p><p>代码如下<span class="Apple-tab-span" ></span></p><p>mysql&gt;flush privileges;</p><p>mysql&gt;select host,user from user where user=&#39;root&#39;;</p><p>mysql&gt;quit</p><p>再次尝试连接后,成功:</p><p><img src="/up_pic/201901/100330494495.png" title="100330494495.png" alt="11.png"/></p>
RangeTime:0.008356s
RangeMem:207.55 KB
返回顶部 留言