Skip to content

Instantly share code, notes, and snippets.

@hkneptune
Last active November 9, 2023 04:01
Show Gist options
  • Save hkneptune/b45c8aeca9b75afaadea1ed527b2c0a2 to your computer and use it in GitHub Desktop.
Save hkneptune/b45c8aeca9b75afaadea1ed527b2c0a2 to your computer and use it in GitHub Desktop.
Install MySQL 8 on CentOS 8 in VirtualBox

Install MySQL 8 on CentOS 8 in VirtualBox

** Please use the root user to edit the files and execute the commands unless further notice. **

Prerequisite

  1. Install the latest VirtualBox Platform Package and the VirtualBox Extension Pack (Oracle_VM_VirtualBox_Extension_Pack-VERSION.vbox-extpack).
  2. Download the latest VirtualBox Guest Additions (VBoxGuestAdditions_VERSION.iso).
  3. Download the latest CentOS Linux release 8.
  4. Create a new virtual machine and install the CentOS to the virtual machine. During the CentOS installation, select Workstation as Base Environment, select Container Management, Development Tools and Graphical Administration Tools as Additional software for Selected Environment. Use http://mirror.centos.org/centos/8/BaseOS/x86_64/os/ as the installation source.
  5. After installing the CentOS, execute the following commands to get the required libraries to create applications for handling compiled objects.
dnf update
dnf install elfutils-libelf-devel
  1. Insert the ISO of VirtualBox Guest Additions to the virtual machine, and then install it.

Add the MySQL Yum/Dandified Yum (dnf) Repository

  1. Download the MySQL Yum Repository from MySQL Website or use the following command to download the RPM file.
wget http://dev.mysql.com/get/mysql80-community-release-el8-1.noarch.rpm
  1. Execute the following command to add the MySQL Yum repository to the system's repository list and download the GnuPG key to verify the integrity of the software packages.
dnf localinstall mysql80-community-release-el8-1.noarch.rpm

Install the MySQL Community Server

  1. Disable the default AppStream repository.
dnf remove @mysql
dnf module reset mysql && sudo dnf module disable mysql
  1. Install the MySQL Community Server.
dnf --enablerepo=mysql80-community install mysql-community-server
  1. Execute the following command to confirm if the installed version is 8.0.
rpm -qi mysql-community-server
  1. Start and enable MySQL service.
systemctl enable --now mysqld.service

First Time Configuration

  1. Use the followikng command to search for the temporary root password.
grep 'A temporary password' /var/log/mysqld.log | tail -1
  1. Execute the following command to complete the installation.
mysql_secure_installation
  1. Enter the temporary root password
Securing the MySQL server deployment.

Enter password for user root:

The existing password for the user account root has expired. Please set a new password.

New password:

Re-enter new password:
The 'validate_password' component is installed on the server.
The subsequent steps will run with the existing configuration
of the component.
Using existing password for root.

Estimated strength of the password: 100
Change the password for root ? ((Press y|Y for Yes, any other key for No) : y

New password:

Re-enter new password:

Estimated strength of the password: 100
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.

Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
Success.


Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : n

 ... skipping.
By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.


Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y
 - Dropping test database...
Success.

 - Removing privileges on test database...
Success.

Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
Success.

All done!

Change the Default Character Set to UTF-8

  1. Open the file /etc/my.cnf and add the followings configurations.
[mysqld]
character-set-client-handshake=FALSE
character-set-server=utf8mb4
collation-server=utf8mb4_unicode_ci
init_connect='SET NAMES utf8mb4'

[client]
default-character-set = utf8mb4

[mysql]
default-character-set = utf8mb4
  1. Restart the MySQL service with the following command.
systemctl restart mysqld

Open Firewall for MySQL Service

  1. Open the port 3306.
firewall-cmd --zone=public --add-port=3306/tcp --permanent
  1. Restart the Firewall service to apply the change.
firewall-cmd --reload

Allow Remote Access with Root Account

  1. Login the MySQL server with the following command, then enter the password.
mysql -u root -h localhost -p
  1. Run the following commands one by one. Set the root user for any host and grant all privileges to the root user.
CREATE USER 'root'@'%' IDENTIFIED BY '<PASSWORD_OF_ROOT_USER>';
USE mysql;
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION;

References

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment