MySQL 8.0 represents a significant advancement in database technology, introducing many enhancements and new features that set it apart from its predecessor, MySQL 5.7. Released in April 2018, this version marks a milestone in MySQL’s journey, catering to the dynamic requirements of developers, database administrators, and organizations globally. The following guide will demonstrate how to install MySQL 8.0 on Fedora Linux, showcasing the steps to leverage the capabilities of this robust database system using Fedora’s repository or the official MySQL Community repository.
Key Features of MySQL 8.0:
- Transactional Data Dictionary: Replacing the older .frm files, MySQL 8.0 introduces a transactional data dictionary stored in InnoDB tables, enhancing metadata management’s reliability and efficiency.
- Atomic Data Definition Language (DDL): This version introduces atomic DDL statements, ensuring data consistency and reducing the risk of database corruption through atomic and crash-safe operations.
- Enhanced JSON Support: MySQL 8.0 significantly improves JSON functionality, offering new functions, optimized storage, and enhanced performance for handling JSON data.
- Comprehensive Unicode Support: With complete support for Unicode 9.0 and improved performance for UTF-8 character sets, MySQL 8.0 can handle a broader array of characters and languages, ideal for global applications.
- Advanced Query Capabilities: Adding Common Table Expressions (CTEs) and Window Functions enables more expressive, efficient query writing, facilitating better management of hierarchical and analytical queries.
- Improved Security Measures: MySQL 8.0 brings security to the forefront with OpenSSL as the default TLS/SSL library, advanced password management, and user-defined roles, ensuring data protection and compliance with industry standards.
- Optimizer Enhancements: The MySQL 8.0 optimizer introduces histograms for optimized query planning, an improved performance schema, and enhanced execution plans, leading to faster query execution and optimized resource utilization.
- InnoDB Storage Engine Upgrades: This latest version significantly improves the InnoDB storage engine, including enhanced support for spatial indexes, full-text search, and optimized performance for read-only workloads.
MySQL 8.0’s robust and versatile features make it an ideal choice for database management tasks. We will now proceed to the installation process.
Table of Contents
Install MySQL 8.0 on Fedora Linux via MySQL RPM
Step 1: Update Fedora Before MySQL 8.0 Installation
Before installing MySQL 8.0, it’s essential to update your Fedora system. This step is vital to avoid compatibility issues and ensure your operating system functions at its best. To update Fedora, use the dnf
package manager.
The following command not only checks for available updates but also installs them:
sudo dnf upgrade --refresh
The --refresh
flag is essential as it forces dnf
to refresh the repository metadata. This means it ensures your system checks against the most current version of packages available, rather than relying on possibly outdated information.
Step 2: Import the Official MySQL 8.0 Community Edition RPM
To install the latest version of MySQL 8.0 Community Edition on Fedora, start by importing the official RPM package.
Copy and paste the following code into your terminal:
sudo tee /etc/yum.repos.d/mysql-8.0.repo<<'EOF'
# MySQL Fedora repository list
[mariadb]
name = MySQL
baseurl = http://repo.mysql.com/yum/mysql-8.0-community/fc/$releasever/$basearch
gpgkey= http://repo.mysql.com/RPM-GPG-KEY-mysql-2022
gpgcheck=1
EOF
The command varies based on your Fedora version.
Step 3: Install MySQL 8.0 Community Server
With the repository set up, proceed to install MySQL 8.0 Community Server:
sudo dnf install mysql-community-server
Step 4: Confirm MySQL Installation
Post-installation, ensure MySQL 8.0 is correctly installed:
mysql --version
This command displays the installed version of MySQL, verifying the successful completion of the installation.
Step 5: Activate MySQL 8.0
Lastly, activate MySQL 8.0 to ensure it’s operational:
sudo systemctl enable mysqld --now
Executing this command starts MySQL immediately and configures it to automatically launch at system start-up, guaranteeing its availability for immediate use and after reboots.
MySQL System Commands Examples with Fedora Linux
Checking the Status of MySQL Service
After installing MySQL 8.0 on Fedora, it’s vital to ensure the MySQL server runs correctly. By default, the service is inactive and not enabled on system start-up.
This can be fixed quickly with the following command:
sudo systemctl enable mysqld --now
Now, run the following command to verify the MySQL service is ok:
systemctl status mysqld
This command provides information about the MySQL service’s current status, including operational status, error messages, or warnings, if any.
Managing the MySQL Service
Stopping the MySQL Service
In specific scenarios, you might need to stop the MySQL service manually. This could be for maintenance purposes or configuration changes. To stop the MySQL service, execute:
sudo systemctl stop mysqld
Starting the MySQL Service
To start the MySQL service, perhaps after a manual stop or maintenance, use this command:
sudo systemctl start mysqld
Disabling Automatic Start-up of MySQL
If you prefer that MySQL does not start automatically when the system boots, you can disable this feature. This might be desirable in a development environment or if you manage system resources closely. Use the following command to disable it:
sudo systemctl disable mysqld
Enabling Automatic Start-up of MySQL
Conversely, if you want MySQL to start automatically with your system’s boot process, enable this feature using:
sudo systemctl enable mysqld
This command is handy for ensuring database availability in production environments.
Restarting the MySQL Service
Sometimes, you may need to restart the MySQL service, especially after configuration changes or updates. To do this, execute:
sudo systemctl restart mysqld
Restarting the service can also help resolve temporary issues without affecting the overall system’s performance. This command stops and then starts the MySQL service in one action.
Secure MySQL 8 with a security script on Fedora Linux
Step 1: Launch MySQL Security Script
When MySQL 8.0 is installed in Fedora, its default settings may not align with stringent security standards. This gap can leave the system vulnerable to unauthorized access. To enhance the security of your MySQL installation, use the mysql_secure_installation
script. This script strengthens MySQL by modifying less secure default options.
Start the security script with this command:
sudo mysql_secure_installation
This initiates a series of prompts to secure your MySQL installation.
Step 2: Handling the Root Password
Initially, MySQL’s root password should be unset. If, for any reason, it’s been set and you don’t have it, you can find the temporary password in the MySQL logs. Retrieve it using:
sudo grep 'temporary password' /var/log/mysqld.log
This command searches the MySQL log file for the temporary password assigned during installation.
Step 3: Configure Security Settings
The security script guides you through various steps to fortify your MySQL setup:
- Setting Root Password: Establish a strong root password if one is not already set or if you wish to change it.
- Securing User Accounts: Assess and secure other MySQL user accounts, ensuring they have strong passwords.
- Limiting Root Access: Remove remote root account access, restricting root privileges to local host connections.
- Removing Anonymous Accounts: Delete anonymous user accounts that don’t have a username, as they can be a significant security risk.
- Eliminating Test Database: The test database, accessible to anonymous users by default, should be removed to prevent unauthorized access to test tables.
The script will prompt you with questions for each step. Enter “Y” to confirm the changes and enhance your MySQL installation’s security. If necessary, you can also reset the root password during this process by following the script’s prompts to create a new one.
[joshua@fedora ~]$ mysql_secure_installation
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: <---- SET NEW PASSWORD
Re-enter new password: <---- RE-ENTER 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 <---- Type Y then press the ENTER KEY (SKIP IF YOU ALREADY JUST SET)
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 <---- Type Y then press the ENTER KEY.
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 <---- Type Y then press the ENTER KEY.
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) : Y <---- Type Y then press the ENTER KEY.
Success.
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 <---- Type Y then press the ENTER KEY.
- 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 <---- Type Y then press the ENTER KEY.
Success.
All done!
Additional Commands For MySQL 8.0 on Fedora Linux
SELinux Troubleshooting
SELinux, a critical security feature in Linux, can sometimes interfere with MySQL operations. If you’re encountering issues with MySQL or MySQL 8.0 Community Server on a system with SELinux, consider adjusting SELinux settings.
Check SELinux Status
First, determine the current status of SELinux:
sestatus
Verify MySQL File Contexts
Check the SELinux context of MySQL’s data directory and socket file:
ls -lZ /var/lib/mysql
ls -lZ /var/lib/mysql/mysql.sock
If the contexts are incorrect, adjust them using:
chcon -Rv --type=mysql_db_t /var/lib/mysql
chcon -v --type=mysql_var_run_t /var/lib/mysql/mysql.sock
Allow Network Access
To permit MySQL network communication under SELinux:
setsebool -P mysql_connect_any 1
Disable SELinux Temporarily
If issues persist, disable SELinux temporarily:
setenforce 0
Connect to the MySQL 8 Terminal Instance
Access MySQL Terminal
Connect to MySQL server as the root user:
sudo mysql -u root -p
Enter the root password set during installation or in the security script.
MySQL Operational Commands
- List Databases: Display all databases:
SHOW DATABASES;
- Selecting a Database: To work with a specific database:
USE database_name;
- Listing Tables: Show tables in the current database:
SHOW TABLES;
- Describing a Table: Get details of a table’s structure:
DESCRIBE table_name;
- Selecting Data: View all data in a table:
SELECT * FROM table_name;
- Inserting Data: Add new data to a table:
INSERT INTO table_name (column1, column2, column3) VALUES (value1, value2, value3);
- Update Data: Modify existing data:
UPDATE table_name SET column_name = value WHERE condition;
- Delete Data: Remove data:
DELETE FROM table_name WHERE condition;
These commands facilitate interaction with MySQL databases from the command line.
Remove MySQL 8.0 From Fedora
For users with MySQL 8.0 installed from the default Fedora repository, use the following command:
sudo dnf remove mysql-community-server
Choose the command based on the version and source of your MySQL installation. This will altogether remove MySQL from your Fedora system.
Lastly, if you have no plans to re-install MySQL 8.0, you can remove the repository with the following command:
sudo rm /etc/yum.repos.d/mysql-8.0.repo
Conclusion
Wrapping up, MySQL has proven to be a robust and highly adaptable open-source database, favored for its scalability and reliability among developers and businesses. This guide took you step-by-step through installing MySQL 8.0 on Fedora, focusing on the installation using the official MySQL RPM. This is a necessary approach since Fedora has shifted to support MariaDB primarily. Alongside the installation, we delved into securing and effectively managing your MySQL setup, emphasizing the importance of regular updates and security measures to maintain a safe and efficient database environment. With these tools and knowledge, you’re well-equipped to manage your data with confidence and precision in MySQL on Fedora. Happy data journey!