MySQL, a robust and widely-used open-source relational database management system, is a cornerstone for many applications, particularly those involving web services. This comprehensive guide will help you install MySQL 8.0 on CentOS 7 or CentOS 6, ensuring a successful setup for your development or production environment.
Prerequisites
- A CentOS 7 or CentOS 6 server
- Root or sudo privileges
- Basic familiarity with Linux terminal commands
Step 1: System Update
Keeping your system updated is crucial for security and compatibility. Begin by updating your system’s packages:
sudo yum update
This command refreshes your package index and updates all your system packages to their latest versions.
Step 2: Adding MySQL Repository
MySQL 8.0 is not available in CentOS’s default package repositories. You need to add MySQL’s official repository to get the latest version:
- Download and install the MySQL repository package:
CentOS 7:
sudo rpm -Uvh https://dev.mysql.com/get/mysql80-community-release-el7-10.noarch.rpm
CentOS 6:
sudo rpm -Uvh https://dev.mysql.com/get/mysql80-community-release-el6-10.noarch.rpm
- Enable the MySQL 8.0 repository:
sudo yum-config-manager --enable mysql80-community
This step ensures that the MySQL 8.0 repository is active.
Step 3: Installing MySQL Server
- Install MySQL:
sudo yum install mysql-community-server
This command installs MySQL along with any necessary dependencies.
- Start the MySQL service:
sudo systemctl start mysqld
This command initiates the MySQL server.
- Enable automatic startup of MySQL on boot:
sudo systemctl enable mysqld
Enabling MySQL to start at boot ensures that the database server is automatically started after a system reboot.
Step 4: Securing MySQL Installation
MySQL’s default settings are not optimized for security. The mysql_secure_installation
script helps in securing your MySQL server.
- Run the security script:
sudo mysql_secure_installation
Set up security options:
- You’ll be prompted to create a root password. Choose a strong, secure password.
- Remove anonymous users to prevent unauthorized access.
- Disallow root login remotely for additional security.
- Remove the test database, which is accessible by default to any user.
Step 5: MySQL Configuration
- Accessing MySQL: Log in to the MySQL shell:
mysql -u root -p
Enter your root password when prompted.
- Editing MySQL Configuration File: The main configuration file for MySQL is
/etc/my.cnf
. Edit this file to change server settings:sudo nano /etc/my.cnf
For example, to set the default character set, add the following under the
[mysqld]
section:[mysqld] character-set-server=utf8mb4
- Restart MySQL: Apply your changes by restarting the MySQL service:
sudo systemctl restart mysqld
Step 6: Verifying MySQL Installation
Ensure that the MySQL service is running smoothly:
sudo systemctl status mysqld
You can also test the setup by creating a new database or user.
Conclusion
Your CentOS 7 or 6 system now has MySQL 8.0 installed and secured. This installation forms the backbone for many applications requiring database management.
Additional Recommendations:
- Regularly back up your MySQL databases to avoid data loss.
- Monitor the performance and logs of MySQL to identify and resolve issues promptly.
- Stay updated on MySQL releases and security patches.
By following this guide, you’ve laid a solid foundation for using MySQL in your applications, empowering you to manage data effectively and securely.
10 Comments
Excellent. Thank you very much. God bless you for sharing the knowledge.
Thank you for clearing the process up. I have been working on this install for two days. The information that I found was useless.
I ran a search, saw the TecAdmin link, which I recognized from previous issues opened the link and 10 minutes later I have a running server and documented install. You make me look good!
With all the confusion around MariaDB/MySQL and CentOS changing hands, it is tedious trying to keep up with all the changes, I need to be producing not floundering. I did not find any mention of the Community repo before this article. I looked too. Reading package notes, and then the MariaDB website, (a big wabbit hole) there was never any mention of the community repo. NONE!
In the future I will look to here first.
Thank you.
Hi, I’m kinda new in this… by the way I need help, what is the password for user root in step 5?, I put the one from the begining of my fedora installation and i tried with the one generated in step 4, both send me an error: access denied for user root…….
Apreciate all your effort, thank you
Hello,
thanks for this valuable post.
I have a question if you or another user can answer it.
Why in mysql 8 the OS user mysql is disabled ? I mean by disabled, we cannot connect to because the shell in /etc/passwd is set to /bin/false ?
It means that for managing mysql service, we will always need to log as root which goes in contradiction with our needs to separate roles.
Any explanation please?
Thanks again for the quality of the post.
You can still login as mysql. I had the same problem with Apache. Use this syntax:
su -s /bin/bash mysql
It will log you in, no spiffy environment settings, useful in so many ways like checking permissions and what not.
Thanks, Very clear and step by step doc…
Thanks my friend. Very neat article.
Very Good. It is very hard to find proper installation documentation guides these days. Your document is very clear and straightforward.
Awesome! Thank you so much. You save too much time for me.
Thank you very much. Very useful tutorial well explained.