SlideShare a Scribd company logo
How to Setup
and Connect
MySQL to
EC2 Instance
from Ubuntu
www.bacancytechnology.com
MYSQL is a famous open-source relational
database management system that provides
scalable and easy-to-use function sets. It
uses a relational DB and Structured Query
Language (SQL) for managing its data.
This tutorial describes a basic MySQL
installation and setup; later we will connect
MySQL to EC2 instance from Ubuntu. Once
done with the basics, we will create a user
for our database.
What is AWS
EC2?
AWS EC2 – AWS Elastic Compute Cloud is
one of the most famous Amazon services
that provides the ability of running the app
on the public cloud. It offers safe, reliable,
and resizable cloud capacity with minimum
obstacles.
I assume that you are quite familiar with
Amazon EC2 and MySQL to proceed with
MySQL Setup in EC2 Ubuntu Instance.
Prerequisites
Create EC2 Ubuntu Instance in AWS
Account
Connect EC2 Instance using SSH or
Putty
To get started with the tutorial for setting
up MySQL in EC2 Ubuntu Instance, please
make sure of the following prerequisites-
Now, let’s move towards how to set up and
connect MySQL to EC2 Instance Ubuntu.
6 Steps to
Setup and
Connect
MySQL to EC2
Instance from
Ubuntu
Step 1: Update System
Packages and Install
MySQL
Run install update for your server system
packages
sudo apt update
Now, install MySQL using the below
command to install the latest MySQL.
sudo apt-get install mysql-server -y
After successful installation of mysql-
server, we can check the MySQL version by
using this command-
mysql --version
Step 2: Configure MySQL
Installation
To configure the installation of MySQL, run
the security script with sudo to run as the
root user- the super privileged user.
Run the below command-
sudo mysql_secure_installation
When we install MySQL for the first time, we
will be prompted to create a new password.
If you are getting an error while setting up
the password, check the temporary
password in the log file.
Use the below command to get a temporary
password.
cat /var/log/mysqld.log
We can find something like this:
Step 3: Login into MySQL
and Create a User
Use the below command to login into
MySQL:
sudo mysql
The command will log in to MySQL using
the root user. Once you are logged in, create
a user in the MySQL database using these
commands:
use mysql;
CREATE USER 'username'@'host'
IDENTIFIED WITH
mysql_native_password BY 'password';
Step 4: Grant Access
Privileges to User
Now, to grant access privileges to this
newly created user, use this command:
GRANT ALL PRIVILEGES ON *.* TO
'username'@'host';
Once this is done, run this command,
FLUSH PRIVILEGES;
Step 5: Connect User with
MySQL
Now you can use this user to connect with
MySQL like this:
mysql -u user -p
Once prompted for a password, provide the
password, and you will be connected.
Trick: If you want to store passwords for
that user, so prompting will not annoy us,
do these things.
Create .my.cnf file inside /home/Ubuntu
path
Write this command:
sudo nano .my.cnf
Write these lines in that file and save.
[mysql]
user=username
password=password
Now, whenever you want to connect, you
can use this .my.cnf file like this, and no
need to provide a password.
mysql --defaults-
file=/home/ubuntu/.my.cnf -u username
This file is generally needed when running
the CI/CD pipeline and connecting to
another server’s MySQL server.
Step 6: Restart MySQL
Service
To affect these changes, restart the MySQL
service by following commands:
to check the status of MySQL service:
systemctl status mysql.service
Now, if it is in “Running” mode, then restart
it using the below command:
sudo service mysql restart
This will restart the service and will reflect
our changes.
Now, your MySQL has been set up in your
Ubuntu Ec2 Instance.
Quick Read:
Cloud Cost Optimization: An Essential
Guide to AWS Cloud Migration
Conclusion
So, this was about how we can set up
MySQL in EC2 Ubuntu Instance. If you have
followed all the steps as discussed above,
then MySQL setup is successfully done in
EC2 Ubuntu Instance. Moreover, we
covered creating a new database and adding
a user to it. For more such tutorials, you can
visit the Cloud Tutorials page to explore
more about Cloud and DevOps services.
Are you looking for a certified architect for
managing AWS services? Then, without
wasting your time, connect us to hire AWS
experts. Bacancy has proficient and
qualified experts with AWS certifications
who have competence in providing
optimum solutions.
Thank You
www.bacancytechnology.com

More Related Content

PDF
ODP
Sql installation
DOC
Installation of Dspace in Windows OS: A Complete Documentation
PPTX
Node Session - 2
PPTX
Node Session - 4
PPT
PPTX
Wordcamp Toronto - Wordpress in the cloud
PPTX
How to install ReactJS software
Sql installation
Installation of Dspace in Windows OS: A Complete Documentation
Node Session - 2
Node Session - 4
Wordcamp Toronto - Wordpress in the cloud
How to install ReactJS software

What's hot (20)

PPTX
Cluster Computing for $0.27/hr using Amazon EC2 and IPython Notebook
DOCX
Multiple instance on windows
PDF
Cookies in Angular | Install CookiesService
PDF
Virtual server on aws
TXT
Intalacion de owncloud
PDF
ember-socket-guru - common api for websockets providers
PPT
Your own minecraft server on a linode vps
PDF
Play Framework in EC2
PDF
Visual Programming Framework for Unity - UniFlow のご紹介
PPT
Core data optimization
PDF
SULTHAN's PHP, MySQL & wordpress
PPT
Mule security - ldap for spring security
PDF
VPNaaS neutron
PPTX
Module 1 introduction to aws demo 4
PPTX
Database systems administration traning 0
DOCX
Terraform bootstrap code_execute
PDF
Standing on the shoulders of Giants
DOCX
Solaris mysql sop
PPTX
Elastic Beanstalk 이용한 Django 배포
PPTX
Dspace for windows
Cluster Computing for $0.27/hr using Amazon EC2 and IPython Notebook
Multiple instance on windows
Cookies in Angular | Install CookiesService
Virtual server on aws
Intalacion de owncloud
ember-socket-guru - common api for websockets providers
Your own minecraft server on a linode vps
Play Framework in EC2
Visual Programming Framework for Unity - UniFlow のご紹介
Core data optimization
SULTHAN's PHP, MySQL & wordpress
Mule security - ldap for spring security
VPNaaS neutron
Module 1 introduction to aws demo 4
Database systems administration traning 0
Terraform bootstrap code_execute
Standing on the shoulders of Giants
Solaris mysql sop
Elastic Beanstalk 이용한 Django 배포
Dspace for windows
Ad

Similar to How to setup and connect my sql to ec2 instance from ubuntu (20)

PPT
Mysql ppt
PPTX
Setting up MySQL Replication Cluster in Kubernetes
PDF
Getting started with my sql
PPTX
Kubernetes - Using Persistent Disks with WordPress and MySQL
PDF
Node.js with MySQL.pdf
DOCX
Mater,slave on mysql
PDF
Kubernetes Hands-On Guide
PDF
How to Install MySQL on Debian 12 In Just 8 Steps.pdf
PDF
Mysql tutorial 5257
PDF
Modulenotfounderror No module named 'mysql' in Python
PDF
Mysql connection
PDF
Python my sql database connection
PDF
Mysql tutorial
DOCX
Connect sql-using-perl-from-linux
PDF
Setting up JupyterHub on AWS
PDF
Scaling on EC2 in a fast-paced environment (LISA'11 - Full Paper)
PDF
How to install and configure lamp (linux,apache mysql mariadb,php) with jooml...
PDF
How to Install Nextcloud on Debian 12.pdf
PDF
Setting up a kubernetes cluster on ubuntu 18.04- loves cloud
PPT
Architecting cloud
Mysql ppt
Setting up MySQL Replication Cluster in Kubernetes
Getting started with my sql
Kubernetes - Using Persistent Disks with WordPress and MySQL
Node.js with MySQL.pdf
Mater,slave on mysql
Kubernetes Hands-On Guide
How to Install MySQL on Debian 12 In Just 8 Steps.pdf
Mysql tutorial 5257
Modulenotfounderror No module named 'mysql' in Python
Mysql connection
Python my sql database connection
Mysql tutorial
Connect sql-using-perl-from-linux
Setting up JupyterHub on AWS
Scaling on EC2 in a fast-paced environment (LISA'11 - Full Paper)
How to install and configure lamp (linux,apache mysql mariadb,php) with jooml...
How to Install Nextcloud on Debian 12.pdf
Setting up a kubernetes cluster on ubuntu 18.04- loves cloud
Architecting cloud
Ad

More from Katy Slemon (20)

PDF
React Alternatives Frameworks- Lightweight Javascript Libraries.pdf
PDF
Data Science Use Cases in Retail & Healthcare Industries.pdf
PDF
How Much Does It Cost To Hire Golang Developer.pdf
PDF
What’s New in Flutter 3.pdf
PDF
Why Use Ruby On Rails.pdf
PDF
How Much Does It Cost To Hire Full Stack Developer In 2022.pdf
PDF
How to Implement Middleware Pipeline in VueJS.pdf
PDF
How to Build Laravel Package Using Composer.pdf
PDF
Sure Shot Ways To Improve And Scale Your Node js Performance.pdf
PDF
How to Develop Slack Bot Using Golang.pdf
PDF
IoT Based Battery Management System in Electric Vehicles.pdf
PDF
Understanding Flexbox Layout in React Native.pdf
PDF
The Ultimate Guide to Laravel Performance Optimization in 2022.pdf
PDF
New Features in iOS 15 and Swift 5.5.pdf
PDF
How to Hire & Manage Dedicated Team For Your Next Product Development.pdf
PDF
Choose the Right Battery Management System for Lithium Ion Batteries.pdf
PDF
Flutter Performance Tuning Best Practices From the Pros.pdf
PDF
Angular Universal How to Build Angular SEO Friendly App.pdf
PDF
How to Set Up and Send Mails Using SendGrid in NodeJs App.pdf
PDF
Ruby On Rails Performance Tuning Guide.pdf
React Alternatives Frameworks- Lightweight Javascript Libraries.pdf
Data Science Use Cases in Retail & Healthcare Industries.pdf
How Much Does It Cost To Hire Golang Developer.pdf
What’s New in Flutter 3.pdf
Why Use Ruby On Rails.pdf
How Much Does It Cost To Hire Full Stack Developer In 2022.pdf
How to Implement Middleware Pipeline in VueJS.pdf
How to Build Laravel Package Using Composer.pdf
Sure Shot Ways To Improve And Scale Your Node js Performance.pdf
How to Develop Slack Bot Using Golang.pdf
IoT Based Battery Management System in Electric Vehicles.pdf
Understanding Flexbox Layout in React Native.pdf
The Ultimate Guide to Laravel Performance Optimization in 2022.pdf
New Features in iOS 15 and Swift 5.5.pdf
How to Hire & Manage Dedicated Team For Your Next Product Development.pdf
Choose the Right Battery Management System for Lithium Ion Batteries.pdf
Flutter Performance Tuning Best Practices From the Pros.pdf
Angular Universal How to Build Angular SEO Friendly App.pdf
How to Set Up and Send Mails Using SendGrid in NodeJs App.pdf
Ruby On Rails Performance Tuning Guide.pdf

Recently uploaded (20)

PPTX
MYSQL Presentation for SQL database connectivity
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
cuic standard and advanced reporting.pdf
PDF
NewMind AI Monthly Chronicles - July 2025
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PPTX
Spectroscopy.pptx food analysis technology
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
solutions_manual_-_materials___processing_in_manufacturing__demargo_.pdf
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Empathic Computing: Creating Shared Understanding
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
KodekX | Application Modernization Development
PDF
Transforming Manufacturing operations through Intelligent Integrations
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
GamePlan Trading System Review: Professional Trader's Honest Take
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
MYSQL Presentation for SQL database connectivity
Chapter 3 Spatial Domain Image Processing.pdf
Network Security Unit 5.pdf for BCA BBA.
cuic standard and advanced reporting.pdf
NewMind AI Monthly Chronicles - July 2025
CIFDAQ's Market Insight: SEC Turns Pro Crypto
Spectroscopy.pptx food analysis technology
Review of recent advances in non-invasive hemoglobin estimation
solutions_manual_-_materials___processing_in_manufacturing__demargo_.pdf
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Empathic Computing: Creating Shared Understanding
Advanced methodologies resolving dimensionality complications for autism neur...
KodekX | Application Modernization Development
Transforming Manufacturing operations through Intelligent Integrations
Per capita expenditure prediction using model stacking based on satellite ima...
GamePlan Trading System Review: Professional Trader's Honest Take
Dropbox Q2 2025 Financial Results & Investor Presentation
Understanding_Digital_Forensics_Presentation.pptx
Diabetes mellitus diagnosis method based random forest with bat algorithm
Reach Out and Touch Someone: Haptics and Empathic Computing

How to setup and connect my sql to ec2 instance from ubuntu

  • 1. How to Setup and Connect MySQL to EC2 Instance from Ubuntu www.bacancytechnology.com
  • 2. MYSQL is a famous open-source relational database management system that provides scalable and easy-to-use function sets. It uses a relational DB and Structured Query Language (SQL) for managing its data. This tutorial describes a basic MySQL installation and setup; later we will connect MySQL to EC2 instance from Ubuntu. Once done with the basics, we will create a user for our database.
  • 4. AWS EC2 – AWS Elastic Compute Cloud is one of the most famous Amazon services that provides the ability of running the app on the public cloud. It offers safe, reliable, and resizable cloud capacity with minimum obstacles. I assume that you are quite familiar with Amazon EC2 and MySQL to proceed with MySQL Setup in EC2 Ubuntu Instance.
  • 6. Create EC2 Ubuntu Instance in AWS Account Connect EC2 Instance using SSH or Putty To get started with the tutorial for setting up MySQL in EC2 Ubuntu Instance, please make sure of the following prerequisites- Now, let’s move towards how to set up and connect MySQL to EC2 Instance Ubuntu.
  • 7. 6 Steps to Setup and Connect MySQL to EC2 Instance from Ubuntu
  • 8. Step 1: Update System Packages and Install MySQL Run install update for your server system packages sudo apt update Now, install MySQL using the below command to install the latest MySQL. sudo apt-get install mysql-server -y After successful installation of mysql- server, we can check the MySQL version by using this command- mysql --version
  • 9. Step 2: Configure MySQL Installation To configure the installation of MySQL, run the security script with sudo to run as the root user- the super privileged user. Run the below command- sudo mysql_secure_installation
  • 10. When we install MySQL for the first time, we will be prompted to create a new password. If you are getting an error while setting up the password, check the temporary password in the log file. Use the below command to get a temporary password.
  • 11. cat /var/log/mysqld.log We can find something like this:
  • 12. Step 3: Login into MySQL and Create a User Use the below command to login into MySQL: sudo mysql The command will log in to MySQL using the root user. Once you are logged in, create a user in the MySQL database using these commands: use mysql; CREATE USER 'username'@'host' IDENTIFIED WITH mysql_native_password BY 'password';
  • 13. Step 4: Grant Access Privileges to User Now, to grant access privileges to this newly created user, use this command: GRANT ALL PRIVILEGES ON *.* TO 'username'@'host'; Once this is done, run this command, FLUSH PRIVILEGES;
  • 14. Step 5: Connect User with MySQL Now you can use this user to connect with MySQL like this: mysql -u user -p Once prompted for a password, provide the password, and you will be connected. Trick: If you want to store passwords for that user, so prompting will not annoy us, do these things. Create .my.cnf file inside /home/Ubuntu path Write this command: sudo nano .my.cnf
  • 15. Write these lines in that file and save. [mysql] user=username password=password Now, whenever you want to connect, you can use this .my.cnf file like this, and no need to provide a password. mysql --defaults- file=/home/ubuntu/.my.cnf -u username This file is generally needed when running the CI/CD pipeline and connecting to another server’s MySQL server.
  • 16. Step 6: Restart MySQL Service To affect these changes, restart the MySQL service by following commands: to check the status of MySQL service: systemctl status mysql.service Now, if it is in “Running” mode, then restart it using the below command: sudo service mysql restart
  • 17. This will restart the service and will reflect our changes. Now, your MySQL has been set up in your Ubuntu Ec2 Instance. Quick Read: Cloud Cost Optimization: An Essential Guide to AWS Cloud Migration
  • 19. So, this was about how we can set up MySQL in EC2 Ubuntu Instance. If you have followed all the steps as discussed above, then MySQL setup is successfully done in EC2 Ubuntu Instance. Moreover, we covered creating a new database and adding a user to it. For more such tutorials, you can visit the Cloud Tutorials page to explore more about Cloud and DevOps services. Are you looking for a certified architect for managing AWS services? Then, without wasting your time, connect us to hire AWS experts. Bacancy has proficient and qualified experts with AWS certifications who have competence in providing optimum solutions.