This guide works with most linux distributions.
Amazon EC2 instances use yum as their default software package
manager. I once needed to install a MySQL server on one of my EC2
instances, So I ran
sudo yum list | grep mysql
to see the available MySQL packages, and I couldn't find anything
related to the MySQL Server (not the client). In this blog, I will
guide you through installing
MySQL Database Server - Community Edition
on an
Amazon EC2 instance.
Let's now jump into the steps!
.rpm
file using
the below command:
wget
https://dev.mysql.com/get/mysql84-community-release-el9-1.noarch.rpm
sudo dnf install mysql84-community-release-el9-1.noarch.rpm
mysql-community-server
is now available through the below command:
sudo yum list | grep mysql-community-server
mysql-community-server.x86_64
sudo yum install mysql-community-server
sudo systemctl start mysqld
sudo lsof -i :3306
mysql -uroot
ERROR 1045 (28000): Access denied for user 'root'@'localhost'
(using password: NO)
my.cnf
file as
below: sudo vim /etc/my.cnf
skip-grant-tables
under
[mysqld]
so
the final contents will be:
# For advice on how to change settings please see
#
http://dev.mysql.com/doc/refman/8.4/en/server-configuration-defaults.html
[mysqld]
skip-grant-tables
#
# Remove leading # and set to the amount of RAM for
the most important data
# cache in MySQL. Start at 70% of total RAM for
dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove the leading "# " to disable binary logging
# Binary logging captures changes between backups and
is enabled by
# default. It's default setting is log_bin=binlog
# disable_log_bin
#
# Remove leading # to set options mainly useful for
reporting servers.
# The server defaults are faster for transactions and
fast SELECTs.
# Adjust sizes as needed, experiment to find the
optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
:wq
, and
then enter.
sudo systemctl restart mysqld
mysql
But now we have an issue: Our Database server stopped listening on
port 3306 because of adding
skip-grant-tables
; so it won't be able to receive requests from our backend code.
Don't worryโI've got you covered. We will solve this issue in part 2
of this blog; you can check it
here.