<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安装成功后创建的超级用户'root'@'localhost'的密码会被存储在/var/log/mysqld.log,可以使用如下命令查看密码</p><p>grep 'temporary password' /var/log/mysqld.log</p><p><img src="/up_pic/201901/100329265126.png" title="100329265126.png" alt="6.png"/></p><p></p><p>使用mysql生成的'root'@'localhost'用户和密码登录数据库,并修改 其密码,具体命令</p><p>shell> mysql -uroot -p</p><p><img src="/up_pic/201901/100329534629.png" title="100329534629.png" alt="7.png"/></p><p>mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass4!';</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>use mysql;</p><p>mysql>update user set host ='%'where user ='root';</p><p>mysql>flush privileges;</p><p></p><p>具体分析</p><p>1、在本机登入mysql后,更改"mysql"数据库里的"user"表里的"host"项,从"localhost"改为'%'。</p><p>代码如下<span class="Apple-tab-span" ></span></p><p>mysql></p><p>mysql>use mysql;</p><p>mysql>select 'host' from user where user='root'; </p><p></p><p> #查看mysql库中的user表的host值(即可进行连接访问的主机/IP名称)</p><p></p><p></p><p>代码如下<span class="Apple-tab-span" ></span></p><p>mysql>update user set host = '%' where user ='root';</p><p>#修改host值(以通配符%的内容增加主机/IP地址,当然也可以直接增加某个特定IP地址,如果执行update语句时出现ERROR 1062 (23000): Duplicate entry '%-root' for key 'PRIMARY' 错误,需要select host from user where user = 'root';</p><p>查看一下host是否已经有了%这个值,如果有了直接执行下面的flush privileges;即可)</p><p>代码如下<span class="Apple-tab-span" ></span></p><p>mysql>flush privileges;</p><p>mysql>select host,user from user where user='root';</p><p>mysql>quit</p><p>再次尝试连接后,成功:</p><p><img src="/up_pic/201901/100330494495.png" title="100330494495.png" alt="11.png"/></p>