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.&nbsp; Log in to a Linux&nbsp;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>.&nbsp;&nbsp;</p> <p>2.&nbsp; 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&nbsp;<span style="font-family:Consolas"><em>xxx&nbsp;</em></span><span style="font-family:Microsoft Yahei">parameter specifies a user-customized&nbsp;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.&nbsp; Add the following content to&nbsp;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&nbsp;<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>&nbsp;.</p> <table border="0" cellpadding="0" cellspacing="0"> <tbody> <tr> <td style="background-color:#f7f8fa"> <p><span style="font-family:Consolas">[<em>mysql</em>] &nbsp; //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.&nbsp; 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 &amp;&amp; yum makecache</span></p> </td> </tr> </tbody> </table> <p>5.&nbsp; 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.&nbsp; 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.&nbsp; Execute the following command to connect to an RDS MySQL instance.</p> <p>&bull;&nbsp; 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>&bull;&nbsp; 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" />:&nbsp;</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&nbsp;number of the&nbsp;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&nbsp;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>&bull;&nbsp; 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>&bull;&nbsp; Connection to the default database: &nbsp;</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
Please complete information!

Call us

400-151-8800

Email us

cloud@pingan.com

Online customer service

Instant reply

Technical Support

cloud products