Installing MySQL Database Server on AWS EC2 - Part 2
This guide works with most linux distributions.
Introduction
This is the second part of my blog about Installing
MySQL Database Server—Community Edition on an
AWS EC2 instance. In part one, we encountered a crucial
issue where our database server stopped listening on port
3306 for security reasons, which was preventing our backend
code from connecting to it. This part will provide the solution to
this significant issue.
If you missed part one, you can still check it
here.
Now, let's dive into the solution!
Solution
The solution is simple; we only have to change the root user's
password and remove the
--skip-grant-tables
we added in the previous part.
Steps
- Ensure you have completed the steps in part one of this blog (you can find it here).
-
Connect to MySQL server using:
mysql -uroot
-
Execute the below
SQL
statements:-
FLUSH PRIVILEGES;
-
ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass';
-
exit;
-
-
Let's now try to connect the same way we did before:
mysql -uroot
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)That means our solution works!
Now try to log in with the password you specified in the previous step:mysql -uroot -p
-
Now, we need to remove the
--skip-grant-tables
we added earlier in the/etc/my.cnf
because they are no longer required. -
Restart mysql:
sudo systemctl restart mysqld
-
Run
sudo lsof -i :3306
-
Login to MySQL:
mysql -uroot -p
- That's it! You have changed the root password, and your instance can now receive requests from your backend code!
Summary
In this blog, we saw how to install MySQL Database
Server—Community Edition on AWS EC2 instances and change the root
account's password.
Remember to remove the
--skip-grant-tables
!