Wei Guang's Blog

Setting up MySQL on AL2023

Follow this quick guide to set up MySQL 8 on AL2023 without any hassle.

Installation

$ curl -sSLO https://dev.mysql.com/get/mysql80-community-release-el7-7.noarch.rpm
$ md5sum mysql80-community-release-el7-7.noarch.rpm
$ sudo rpm -ivh mysql80-community-release-el7-7.noarch.rpm
$ sudo yum install mysql-server

You may wonder where to obtain the name of the RPM. Here is the source: https://dev.mysql.com/downloads/repo/yum/. Basically, mysql80-community-release-el9-1.noarch.rpm also works. You can choose the one you prefer.

Starting the Server

$ sudo systemctl start mysqld

Check the status of the server to verify whether it started successfully or not.

$ sudo systemctl status mysqld

Connecting to the Server

First, you need to find out the initial password by executing the following command:

$ sudo grep 'temporary password' /var/log/mysqld.log

You will get something like this:

root@localhost: abcxxxxxx # <- The initial password

Now, you can connect to your MySQL server using the following command:

$ mysql -u root -p
# Enter the initial password

Before you can create any databases, you need to modify your initial password. Here's how you can do it:

$ mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'Enter your new password here';

Once you have done that, make sure to use the new password to connect to your MySQL server next time.

Additionally, if you want a password-free connection, you can follow these steps:

  1. Open or create the .my.cnf file:
$ sudo vim ~/.my.cnf
  1. Put the following configuration into the file:
# Add the following lines
# [client]
# user="root"
# password="your password"

From then on, when you want to connect to MySQL, just type mysql, and it will automatically authenticate for you.

Good luck.