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.
- 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:
sudo rpm -Uvh https://dev.mysql.com/get/mysql80-community-release-el7-10.noarch.rpm
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:
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
- 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.
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.
- 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.