How to enable remote access for MySQL on EC2

Source: Internet
Author: User
Recently, MySQL was installed on an Amazon cloud host and cannot be accessed remotely. After several pitfalls, the access was successful. Here we will record: EC2

Recently, MySQL was installed on an Amazon cloud host and cannot be accessed remotely. After several pitfalls, the access was successful. Here we will record: EC2

Recently, MySQL was installed on an Amazon cloud host and cannot be accessed remotely. After several pitfalls, the access was successful. Here we will record how to enable remote access after MySQL is installed on EC2.

I. Problems Encountered

To remotely access MySQL on EC2, the following message is displayed:
ERROR 2003 (HY000): Can't connect to MySQL server on 'xx. xx. xx. xx' (111)
Or
Host 'xx. xx. xx. xx' is not allowed to connect to this MySQL server

Ii. Solutions

1. Set the EC2 Firewall

EC2's default firewall blocks all traffic. Therefore, in addition to other necessary rules in EC2's Scurity Groups, you must add an ingress traffic rule: any source IP connection of port 3306 of TCP is allowed.

2. Set User Access in MySql

By default, MySQL only allows access from the local machine. To enable remote access, run the following commands in Terminal:

Mysql-u root-p
Use mysql
Update user set Host = '%' where User = 'root'

In this way, you can access MySql from any IP address.

3. Bind IP addresses in MySQL

Sudo vim/etc/mysql/my. cnf1

Change bind-address 127.0.0.1 to bind-address 0.0.0.0, so that the EC2 IP address can be remotely accessed regardless of the change.

4. Restart MySQL

Sudo/etc/init. d/mysql restart1

The following is the MySQL-related content carefully selected by the editor to see if it is helpful:

Install MySQL 5.6 with the source code in CentOS 7

How to install and configure MySQL5.7.3.0

Install MySQL in Ubuntu 14.04

MySQL authoritative guide (original book version 2nd) Clear Chinese scan PDF

Ubuntu 14.04 LTS install LNMP Nginx \ PHP5 (PHP-FPM) \ MySQL

Build a MySQL Master/Slave server in Ubuntu 14.04

Build a highly available distributed MySQL cluster using Ubuntu 12.04 LTS

Install MySQL5.6 and Python-MySQLdb in the source code of Ubuntu 12.04

MySQL-5.5.38 universal binary Installation

This article permanently updates the link address:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.