Connection in Linux Operating System
<p>This article describes how to install MySQL client on the ECS in Linux operating system and access an RDS MySQL instance via the MySQL client.</p>
<p><span style="font-size:18px"><strong>Prerequisites</strong></span></p>
<ol>
<li>You have successfully bound an account and a database. For more information, see <a href="http://pinganyun.com/ssr/help/database/RDS/Getting_Started.RDS_MySQL.Binding_Account" target="_blank">Authorize Permission of Account and Database</a>.</li>
<li>You have successfully created an ECS. For more information, see <a href="http://pinganyun.com/ssr/help/database/RDS/Getting_Started.RDS_MySQL.Create_ECS" target="_blank">Create an ECS</a>, and the instance is in the status of running.</li>
<li>You have successfully opened a whitelist. For more information, see <a href="http://pinganyun.com/ssr/help/database/RDS/Getting_Started.RDS_MySQL.Create_Whitelist" target="_blank">Open a Whitelist</a>.</li>
</ol>
<p><span style="font-size:18px"><strong>Usage Guidelines</strong></span></p>
<p>If SSL encryption is needed, the version of MySQL client should be equal to or higher than 5.6.38.</p>
<p><span style="font-size:18px"><strong>Procedures</strong></span></p>
<p>1. Log in to a Linux ECS instance. For more information, see <a href="http://pinganyun.com/ssr/help/compute/ecs/Quick_Start.Linux_Quick_Start.Login_Instance" target="_blank">Log In to Instance</a>. </p>
<p>2. Execute the following command to open xxx.repo file.</p>
<p><img src="https://obs-cn-shanghai.yun.pingan.com/pcp-portal/20200207135414-124ec9da9e19.png" style="height:22px; margin:0px; width:90px" />: The <span style="font-family:Consolas"><em>xxx </em></span><span style="font-family:Microsoft Yahei">parameter specifies a user-customized file name</span><span style="font-family:Consolas">.</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. Add the following content to the xxx.repo file.</p>
<p><img src="https://obs-cn-shanghai.yun.pingan.com/pcp-portal/20200207135414-124ec9da9e19.png" style="height:22px; margin:0px; width:90px" />: If MySQL 8.0 is used, you must use the client for MySQL 8.0 to access the MySQL instance, and replace <span style="font-family:Consolas">mysql80-community-el7 </span><span style="font-family:Microsoft Yahei">with</span><span style="font-family:Consolas"> mysql57-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>] //Customize the name based on your need.</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. Execute the following command to update yum installation source.</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. Execute the following command to disable the default MySQL software.</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. Execute the following command to install MySQL client.</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. Execute the following command to connect to an RDS MySQL instance.</p>
<p>• To connect to a specific database, specify the following connection parameters:</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>• If you do not specify connection parameters, you are connected to the default database.</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://obs-cn-shanghai.yun.pingan.com/pcp-portal/20200207135414-124ec9da9e19.png" style="height:22px; margin:0px; width:90px" />: </p>
<ul>
<li>-h<em>Domain-Name</em>: Domain name of the RDS MySQL instance. For more information, see <a href="http://pinganyun.com/ssr/help/database/RDS/User_Guide_RDS_MySQL.Instance_Management.View_Instance.View_Common_Instance" target="_blank">View Basic Information about an Instance</a>.</li>
<li>-u<em>Mysql_Account</em>: Account name that has been created. For more information, see <a href="http://pinganyun.com/ssr/help/database/RDS/User_Guide_RDS_MySQL.Account.Create_Account" target="_blank">Create an Account</a>.</li>
<li>-D<em>Database-name</em>: Name of the database that has been created. For more information, see <a href="http://pinganyun.com/ssr/help/database/RDS/User_Guide_RDS_MySQL.Database.Create_Database" target="_blank">Create Database</a>.</li>
<li>-P<em>Port</em>: Port number of the RDS MySQL instance. For more information, see <a href="http://pinganyun.com/ssr/help/database/RDS/User_Guide_RDS_MySQL.Instance_Management.View_Instance.View_Common_Instance" target="_blank">View Basic Information about an Instance</a>.</li>
<li>-p<em>Password</em>: Password that you have set for the account. For more information, see <a href="http://pinganyun.com/ssr/help/database/RDS/User_Guide_RDS_MySQL.Account.Create_Account" target="_blank">Create an Account</a>.</li>
</ul>
<p><span style="font-size:18px"><strong>Result</strong></span></p>
<p>The client is successfully connected to the RDS MySQL instance.</p>
<p>• Connection to the specified database:</p>
<p><img src="https://obs-cn-shanghai.yun.pingan.com/pcp-portal/20191507115638-1846e49e9d04.png" style="height:229px; width:667px" /></p>
<p>• Connection to the default database: </p>
<p><img src="https://obs-cn-shanghai.yun.pingan.com/pcp-portal/20191507115631-16b69b029ef7.png" style="height:393px; width:576px" /></p>
Did the above content solve your problem?
Yes
No
Submitted successfully! Thank you for your feedback, we will try our best to do better and better!