Linux系统连接
<p>本文主要介绍如何在Linux操作系统的ECS上安装MySQL客户端,并通过MySQL客户端访问RDS-MySQL实例。</p>
<p><span style="font-size:18px"><strong>前提条件</strong></span></p>
<p>1. 您已成功绑定账号与数据库,可参考<a href="https://pinganyun.com/ssr/help/database/RDS/Getting_Started.RDS_MySQL.Binding_Account" target="_blank">授权账号与数据库权限</a>。</p>
<p>2. 您已成功创建ECS,可参考<a href="https://pinganyun.com/ssr/help/database/RDS/Getting_Started.RDS_MySQL.Create_ECS" target="_blank">创建ECS</a>,且实例处于运行中。</p>
<p>3. 您已成功开通白名单,可参考<a href="https://pinganyun.com/ssr/help/database/RDS/Getting_Started.RDS_MySQL.Create_Whitelist" target="_blank">开通白名单</a>。</p>
<p><span style="font-size:18px"><strong>注意事项</strong></span></p>
<ul>
<li>若需要执行SSL加密功能,MySQL客户端的版本需要大于等于5.6.38。</li>
<li>ECS的操作系统请选择CentOS 7.x、RedHat Linux 7.x、Oracle Linux 7.x及以上的版本。</li>
</ul>
<p><span style="font-size:18px"><strong>操作步骤</strong></span></p>
<p>1. 登录ECS,可参考<a href="https://pinganyun.com/ssr/help/compute/ecs/Quick_Start.Linux_Quick_Start.Login_Instance" target="_blank">登录Linux云主机</a>。 </p>
<p>2. 执行以下命令打开<span style="font-family:Consolas"><em>xxx</em>.repo</span>文件。</p>
<p><img src="https://pcp-portal-sca.obs-cn-shenzhen.pinganyun.com/pcp-portal-sca/20191507115614-1724ebbe9ee1.png" style="height:26px; margin:0px; width:65px" />:<span style="font-family:Consolas"><em>xxx</em>:文件名称,您可以根据实际情况自定义。</span></p>
<table border="0" cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td style="background-color:#f7f8fa">
<p><span style="font-family:Consolas">cd /etc/yum.repos.d</span></p>
<p><span style="font-family:Consolas">vim xxx.repo</span></p>
</td>
</tr>
</tbody>
</table>
<p>3. 在<span style="font-family:Consolas"><em>xxx</em>.repo</span>文件中增加以下内容。</p>
<p><img src="https://pcp-portal-sca.obs-cn-shenzhen.pinganyun.com/pcp-portal-sca/20191507115614-1724ebbe9ee1.png" style="height:26px; margin:0px; width:65px" />:若MySQL的版本是8.0,需要使用MySQL 8.0的客户端进行访问。同时将<span style="font-family:Consolas">mysql57-community-el7</span>替换为<span style="font-family:Consolas">mysql80-community-el7</span>。</p>
<table border="0" cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td style="background-color:#f7f8fa">
<p><span style="font-family:Consolas">[<em>mysql</em>] //您可以根据实际情况自定义名称</span></p>
<p><span style="font-family:Consolas">name=mysql57-community-el7</span></p>
<p><span style="font-family:Consolas">baseurl=http://yum.cloud.papub/mysql/yum/mysql57-community-el7/</span></p>
<p><span style="font-family:Consolas">enabled=1</span></p>
<p><span style="font-family:Consolas">gpgcheck=0</span></p>
</td>
</tr>
</tbody>
</table>
<p>4. 执行以下命令,更新yum源。</p>
<table border="0" cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td style="background-color:#f7f8fa">
<p><span style="font-family:Consolas">yum clean all && yum makecache</span></p>
</td>
</tr>
</tbody>
</table>
<p>5. 执行以下命令,屏蔽默认的MySQL软件。</p>
<table border="0" cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td style="background-color:#f7f8fa">
<p><span style="font-family:Consolas">yum -qy module disable mysql</span></p>
</td>
</tr>
</tbody>
</table>
<p>6. 执行以下命令,安装MySQL客户端。</p>
<table border="0" cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td style="background-color:#f7f8fa">
<p><span style="font-family:Consolas">yum install mysql</span></p>
</td>
</tr>
</tbody>
</table>
<p>7. 执行以下命令,连接RDS-MySQL实例。</p>
<p>• 指定数据库连接: </p>
<table border="0" cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td style="background-color:#f7f8fa">
<p><span style="font-family:Consolas">mysql -h<em>Domain-name</em> -u<em>Mysql_Account</em> -D<em>Database-name</em> -P<em>Port</em> -p<em>Password</em></span></p>
</td>
</tr>
</tbody>
</table>
<p>• 不指定数据库连接,会连接至默认的系统数据库。</p>
<table border="0" cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td style="background-color:#f7f8fa">
<p><span style="font-family:Consolas">mysql -h<em>Domain-name</em> -u<em>Mysql_Account</em> -P<em>Port</em> -p<em>Password</em></span></p>
<p><span style="font-family:Consolas">use <em>Database-name</em></span></p>
</td>
</tr>
</tbody>
</table>
<p><img src="https://pcp-portal-sca.obs-cn-shenzhen.pinganyun.com/pcp-portal-sca/20191507115614-1724ebbe9ee1.png" style="height:26px; margin:0px; width:65px" />:</p>
<p>• -h<em>Domain-Name</em>:RDS-MySQL实例的<strong>访问域名</strong>,可参考<a href="https://pinganyun.com/ssr/help/database/RDS/User_Guide_RDS_MySQL.Instance_Management.View_Instance.View_Common_Instance" target="_blank">查看实例基本信息</a>。</p>
<p>• -u<em>Mysql_Account</em>:创建的账号名,可参考<a href="https://pinganyun.com/ssr/help/database/RDS/User_Guide_RDS_MySQL.Account.Create_Account" target="_blank">创建用户</a>。</p>
<p>• -D<em>Database-name</em>:创建的数据库名,可参考<a href="https://pinganyun.com/ssr/help/database/RDS/User_Guide_RDS_MySQL.Database.Create_Database" target="_blank">创建数据库</a>。</p>
<p>• -P<em>Port</em>:RDS-MySQL实例的<strong>连接端口</strong>,可参考<a href="https://pinganyun.com/ssr/help/database/RDS/User_Guide_RDS_MySQL.Instance_Management.View_Instance.View_Common_Instance">查看实例基本信息</a>。</p>
<p>• -p<em>Password</em>:创建用户时设置的<strong>密码</strong>,可参考<a href="https://pinganyun.com/ssr/help/database/RDS/User_Guide_RDS_MySQL.Account.Create_Account">创建用户</a>。</p>
<p><span style="font-size:18px"><strong>执行结果</strong></span></p>
<p>成功连接RDS-MySQL实例。</p>
<p>• 指定数据库连接 </p>
<p><img src="https://pcp-portal-sca.obs-cn-shenzhen.pinganyun.com/pcp-portal-sca/20191507115638-1846e49e9d04.png" style="height:229px; width:667px" /></p>
<p>• 不指定数据库连接 </p>
<p><img src="https://pcp-portal-sca.obs-cn-shenzhen.pinganyun.com/pcp-portal-sca/20191507115631-16b69b029ef7.png" style="height:393px; width:576px" /></p>
提交成功!非常感谢您的反馈,我们会继续努力做到更好!