Install MySQL 5.7 on CentOS 8

Recently, I was working on a project where I had WordPress running on CentOS 8. However, we were using MariaDB and needed to change to a MySQL 5.7 database to meet other needs of the project.

The following outlines the process of setting up MySQL 5.7, the remaining portions of a LAMP environment, and WordPress on a CentOS 8 instance.

1. Disable MySQL default AppStream repository:

sudo yum remove @mysql

2. Use this command to create a new EL 7 repository file:

sudo vi /etc/yum.repos.d/mysql-community.repo

3. Paste the text below into the file:

[mysql57-community]
name=MySQL 5.7 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/7/$basearch/
enabled=1
gpgcheck=0

[mysql-connectors-community]
name=MySQL Connectors Community
baseurl=http://repo.mysql.com/yum/mysql-connectors-community/el/7/$basearch/
enabled=1
gpgcheck=0

[mysql-tools-community]
name=MySQL Tools Community
baseurl=http://repo.mysql.com/yum/mysql-tools-community/el/7/$basearch/
enabled=1
gpgcheck=0

4. Install MySQL 5.7 on CentOS 8

sudo yum –enablerepo=mysql57-community install mysql-community-server

5. Type ‘y’ for Yes

6. After the installation, start mysqld service

sudo systemctl enable –now mysqld.service

7. Create random password for the MySQL root user

sudo grep ‘A temporary password’ /var/log/mysqld.log |tail -1

8. Continuing MySQL 5.7 installation:

sudo mysql_secure_installation

9. Enter new password for root user.

10. YES – to remove anonymous users, disallow remote root login, remove test database, remove privileges on test database, and reload the privilege tables now.

11. Use this command to connect to MySQL:

sudo mysql -u root -p

12. You can run the following command at the mysql> command prompt to check version:

mysql> SELECT VERSION();

13. Create a database:

CREATE DATABASE testXYZdb;

14. Create a database user:

CREATE USER ‘testXYZuser’@’localhost’ IDENTIFIED BY “RandomWord12!”;

15. Grant all privileges for that user on the database:

GRANT ALL PRIVILEGES ON testXYZdb.* TO ‘testXYZuser’@’localhost’;

16. Flush privileges table:

FLUSH PRIVILEGES;

17. Quit MySQL by simply typing:

quit

18. Install remi repository on CentOS 8:

sudo yum -y install http://rpms.remirepo.net/enterprise/remi-release-7.rpm

19. Install and update yum utitilites:

sudo yum install yum-utils

20. Disable PHP 5.4

sudo yum-config-manager –disable remi-php54

21. Enable PHP 7.3

sudo yum-config-manager –enable remi-php73

22. Install remaining LAMP dependencies

sudo yum install httpd php php-common php-mysql php-gd php-xml php-mbstring php-mcrypt

23. Stop nginx web service

sudo service nginx stop

24. Disable nginx from system startup

sudo systemctl disable nginx

25. Start apache httpd web service

sudo systemctl start httpd

26. Enable apache httpd on system startup

sudo systemctl enable httpd

27. Change to the following directory:

cd /var/www

28. Install wget on CentOS 8:

sudo yum install wget

29. Get the latest WordPress archive:

sudo wget https://wordpress.org/latest.tar.gz

30. Extract the WordPress archive:

sudo tar xvzf latest.tar.gz

31. Remove the WordPress archive:

sudo rm -v latest.tar.gz

32. Make apache the owner of the /wordpress/ directory

sudo chown -Rf apache:apache ./wordpress/

33. Changing the file permissions of the /wordpress/ directory

sudo chmod -Rf 775 ./wordpress/

34. Create a WordPress configuration file for apache:

sudo vi /etc/httpd/conf.d/wordpress.conf

35. Hit i to insert, add the following text, and then ESC !wq in order to save and quit the file

<VirtualHost *:80>
ServerAdmin root@localhost
DocumentRoot /var/www/wordpress
<Directory “/var/www/wordpress”>
Options Indexes FollowSymLinks
AllowOverride all
Require all granted
</Directory>
ErrorLog /var/log/httpd/wordpress_error.log
CustomLog /var/log/httpd/wordpress_access.log common
</VirtualHost>

36. Restart Apache web service

sudo systemctl restart httpd

38. In a browser enter your domain name and continue installing WordPress through the browser installation screens.

Leave a Reply

Your email address will not be published. Required fields are marked *