MySQL 8.0 is a popular and widely used open-source relational database management system. It was first released in April 2018 and was developed and maintained by Oracle Corporation. MySQL 8.0 is a major update that includes significant improvements in performance, security, and scalability.
One of the main reasons for MySQL’s popularity is its ease of use and flexibility. It is a highly scalable database system that can be used for many applications, from small websites to large-scale enterprise systems. Its ability to handle high traffic and large data sets makes it an ideal choice for many businesses.
MySQL 8.0 has several new features and enhancements that further increase its popularity. For example, it includes support for window functions, which makes it easier to perform complex queries on large data sets. It also includes support for common table expressions (CTEs), simplifying the creation of more advanced SQL queries.
In addition to these features, MySQL 8.0 includes improved security measures, such as stronger password policies and support for roles. These security features help protect data from unauthorized access and ensure that only authorized users can access and modify the database.
Installing MySQL 8.0 on Fedora is a straightforward process that can be done using the command line terminal. This guide will show you how to install MySQL 8.0 on Fedora using either the standard default version in Fedora’s repository or the latest version from MySQL’s official RPM and installing the MySQL 8.0 Community Edition.
By the end of this guide, you will have a working installation of MySQL 8.0 on your Fedora system, ready to use for your applications or projects. Whether you are a developer or a system administrator, this guide will help you get up and running with MySQL 8.0 quickly and easily.
Table of Contents
It is crucial to keep your system up-to-date to prevent potential issues during the installation of MySQL 8.0 and ensure the optimal functionality of your Fedora operating system. To achieve this, execute the following command, which will allow you to check for and install any available updates for your operating system:
sudo dnf upgrade --refresh
Method 1: Install MySQL 8.0 with Fedora Repository
The installation of MySQL 8.0 on Fedora can be done in several ways. One of the methods involves using the Fedora repository to install MySQL 8.0. Fedora updates its packages frequently, making it an excellent distribution for those who desire the latest packages.
To check for the availability of other MySQL versions, execute the following command:
sudo dnf module list mysql
Example output from dnf module MySQL command:
If you are using the default installation of Fedora, MySQL 8.0 is likely to be the only available version, displayed with the [d] flag. To enable MySQL 8.0, execute the following command:
sudo dnf module enable mysql:8.0
Once MySQL 8.0 has been enabled, proceed to install MySQL and MySQL server by running the following command:
sudo dnf install mysql mysql-server
After the installation of MySQL 8.0 on your Fedora operating system, it is essential to verify that the installation was successful before proceeding to use it. To check the version of MySQL that was installed, run the following command:
Once you have confirmed the installation, it is crucial to activate MySQL 8.0 to ensure it is running correctly. To activate MySQL 8.0, execute the following command:
sudo systemctl enable mysqld --now
This command will start MySQL in your current session and automatically restart it on future system reboots.
Method 2: Install MySQL 8.0 Community Edition
If you require the latest version of MySQL 8.0, install it on your Fedora operating system by following the steps below.
Begin by importing the official RPM for the MySQL 8.0 community edition by using the following command:
To import the MySQL 8.0 Community Edition for Fedora 37, use the following command:
sudo rpm -ivh https://dev.mysql.com/get/mysql80-community-release-fc37-1.noarch.rpm
To import the MySQL 8.0 Community Edition for Fedora 36, use the following command:
sudo rpm -ivh https://dev.mysql.com/get/mysql80-community-release-fc36-1.noarch.rpm
After the import, you can verify that the repository was successfully added by using the following command:
dnf repolist all | grep mysql | grep enabled
Next, you can install the MySQL 8.0 Community Server using the following command:
sudo dnf install mysql-community-server
Upon completion of the installation, you can confirm the build of the MySQL 8.0 version by running the following command:
Finally, you can activate MySQL 8.0 using the following command:
sudo systemctl enable mysqld --now
This command will start MySQL in your current session and automatically restart it on future system reboots, ensuring it is always available.
MySQL System Commands
After installing MySQL 8.0 on your Fedora system, verifying that the MySQL server is operational is crucial. The installer automatically starts the default MySQL service and configures it to start automatically on system startup. To check the status of the MySQL service, execute the following command:
systemctl status mysqld
This command will display the current status of the MySQL service, including any error messages or warnings.
Sometimes, it may be necessary to stop or start the MySQL service manually. To stop the MySQL service, use the following command:
sudo systemctl stop mysqld
Conversely, to start the MySQL service, use the following command:
sudo systemctl start mysqld
If you do not want the MySQL service to start automatically on system startup, you can disable it by using the following command:
sudo systemctl disable mysqld
If you prefer to enable the MySQL service to start automatically on system startup, use the following command:
sudo systemctl enable mysqld
Finally, if you need to restart the MySQL service for any reason, execute the following command:
sudo systemctl restart mysqld
Secure MySQL 8 with a security script
When installing MySQL 8.0 on your Fedora operating system, the default settings may be considered weak by many security standards, potentially allowing hackers to exploit the system. To address this issue, you can run the installation security script, which provides an additional layer of security to your MySQL installation.
Begin by launching the security script by executing the following command:
By default, the root password for MySQL should be blank. However, if the password has been set for some reason, you can generate a temporary password to log into the MySQL security script by executing the following command:
sudo grep 'temporary password' /var/log/mysqld.log
During the configuration process, the script will guide you through the following steps:
- Setting the password for root accounts.
- Setting the password for other accounts.
- Removal of root accounts accessible from outside the local host.
- Removal of anonymous user accounts.
- Removal of the test database is accessible by default to anonymous users.
You will be prompted with a series of questions, and you can delete everything by entering “Y” when prompted. If you prefer, you can also reset your root password by creating a new one. Follow the prompts to create a new password, set the root account permissions, remove the test database, and reload the privilege tables.
Here is an example of the output that you can expect when running the script:
[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!
If you are experiencing issues with SELinux and MySQL or MySQL 8.0 Community Server from MySQL repositories, you may need to adjust some SELinux settings. SELinux is a security mechanism in Linux that can cause problems with MySQL installations. Here are some SELinux commands that may help troubleshoot issues with MySQL:
- Check the current status of SELinux:
- Check the SELinux context of the MySQL data directory and socket file:
ls -lZ /var/lib/mysql ls -lZ /var/lib/mysql/mysql.sock
- If the context of the MySQL data directory and socket file is not correct, you can change it using the following command:
chcon -Rv --type=mysql_db_t /var/lib/mysql chcon -v --type=mysql_var_run_t /var/lib/mysql/mysql.sock
- If SELinux is preventing MySQL from accessing the network, you can run the following command to allow MySQL to communicate over the network:
setsebool -P mysql_connect_any 1
- If you are still experiencing issues with SELinux, you can temporarily disable it using the following command:
Connect to the MySQL 8 Terminal Instance
To connect to the MySQL 8 terminal instance and run common commands, follow these steps:
Open the terminal and enter the following command to connect to the MySQL server as the root user:
sudo mysql -u root -p
You will be prompted to enter the root password you defined in the installation configuration or the post-installation security script.
Once inside the MySQL service instance, you can run the following command to list all the available databases on the server:
To select the specified database as the default database to use for future commands, use the following command:
You can run the following command to list all the tables in the current database:
To get a description of the specified table, including its columns and their data types, use the following command:
To retrieve all the data from the specified table, use the following command:
SELECT * FROM table_name;
To insert data into the specified table, use the following command:
INSERT INTO table_name (column1, column2, column3) VALUES (value1, value2, value3);
To update data in the specified table that meets the specified condition, use the following command:
UPDATE table_name SET column_name = value WHERE condition;
To delete data from the specified table that meets the specified condition, use the following command:
DELETE FROM table_name WHERE condition;
By using these commands, you can interact with the MySQL databases and manipulate the data stored in them from the command line.
Remove (Uninstall) MySQL 8.0
If you have decided that you no longer need the MySQL database and want to remove it completely, you can do so by running the appropriate command, depending on the version of MySQL that you have installed.
For users with MySQL 8.0 installed from the default Fedora repository, use the following command:
sudo dnf remove mysql
For users with MySQL 8.0 Community Edition installed, use the following command:
sudo dnf remove mysql-community-server
In conclusion, MySQL is a powerful and widely used open-source relational database management system that is popular among developers and businesses for its scalability, flexibility, and reliability. In this guide, we have demonstrated how to install MySQL 8.0 on Fedora using the command line terminal, either with the default version in Fedora’s repository or by installing the MySQL 8.0 Community Edition. We have also covered how to secure your MySQL installation using the security script, connect to the MySQL terminal instance, and run common MySQL commands. Following the steps outlined in this guide, you can effectively manage your MySQL databases and use them to store, retrieve, and manipulate your data securely and efficiently.
FAQs on MySQL 8.0 with Fedora
Q: What is MySQL?
A: MySQL is a popular open-source relational database management system that allows users to store, retrieve, and manipulate data in a structured manner. It is widely used in web development, enterprise software, and other applications that require a reliable and scalable database management system.
Q: What version of MySQL should I use on Fedora?
A: The default version of MySQL in the Fedora repository is typically the most up-to-date version and is recommended for most users. However, if you require the latest features or bug fixes, you may want to install MySQL 8.0 Community Edition.
Q: How do I secure my MySQL installation?
A: You can use the post-installation security script to secure your MySQL installation. The script will prompt you to set a new root password, remove anonymous users and test databases, and restrict root access from remote machines.
Q: How do I connect to my MySQL database?
A: You can connect to your MySQL database by launching the MySQL terminal instance using the mysql command and entering your root password. Once inside the terminal instance, you can execute various SQL commands to manage your databases.
Q: What are some common MySQL commands that I should know?
A: Some common MySQL commands that you may find useful include
SELECT (to retrieve data from a table),
INSERT (to add data to a table),
UPDATE (to modify data in a table),
DELETE (to remove data from a table),
CREATE (to create a new table),
ALTER (to modify the structure of a table), and
DROP (to delete a table).
Q: Can I use MySQL with other programming languages?
A: Yes, MySQL can be used with various programming languages, including PHP, Java, Python, and more. Many libraries and frameworks can also help you integrate MySQL with your chosen programming language.
Q: Is MySQL free to use?
A: Yes, MySQL is open-source software available under the GPL (General Public License) or a commercial license for those requiring additional support and features. This means anyone can download, use, and modify the software without paying fees.
Q: Can I use MySQL in a production environment?
A: Yes, MySQL is a reliable and scalable database management system suitable for production environments. However, it is important to properly secure your installation and follow best practices to ensure the safety and integrity of your data.