MySQL is one of the most popular open-source relational database management systems (RDBMS). In this comprehensive guide, we will walk you through the process of how to set up a MySQL database server on Oracle Linux. Oracle Linux is a great choice for running MySQL, as it provides a stable and secure environment, as well as excellent performance. Let’s dive in!
Table of Contents
- Prerequisites
- Installing MySQL
- Configuring MySQL
- Securing MySQL
- Managing MySQL Services
- Creating and Managing MySQL Databases
- Conclusion
Prerequisites
Before we begin, ensure that you have:
- Oracle Linux 7 or 8 is installed on your server.
- A user account with
sudo
privileges. - A stable internet connection.
How to Set Up a MySQL Database Server on Oracle Linux
Installing MySQL
First, let’s update the system packages and install any necessary dependencies:
sudo yum update -y
sudo yum install -y wget
Next, download the MySQL Yum repository:
wget https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
Install the repository using yum
:
sudo yum localinstall mysql80-community-release-el7-3.noarch.rpm
Now, install MySQL:
sudo yum install -y mysql-community-server
Once the installation is complete, start the MySQL service and enable it to start at boot:
sudo systemctl start mysqld
sudo systemctl enable mysqld
Configuring MySQL
After installing MySQL, you must configure it for optimal performance and security. First, let’s retrieve the default root
password:
sudo grep 'temporary password' /var/log/mysqld.log
Take note of the password, as you’ll need it to log in to MySQL in the next step. Now, log in to MySQL:
mysql -u root -p
Enter the temporary password when prompted. Once logged in, change the root
password:
ALTER USER 'root'@'localhost' IDENTIFIED BY 'NewSecurePassword';
Replace NewSecurePassword
with a strong password of your choice.
Securing MySQL
Next, run the MySQL security script to secure your installation further:
sudo mysql_secure_installation
This script will prompt you to:
- Change the
root
password (you can skip this since you’ve already done it) - Remove anonymous users
- Disallow remote
root
login - Remove the test database and access to it
- Reload privilege tables
Follow the prompts and answer accordingly to enhance the security of your MySQL installation.
Managing MySQL Services
To ensure that your MySQL server is running smoothly, it’s essential to know how to manage its services. Here are some basic commands:
Start MySQL:
sudo systemctl start mysqld
Stop MySQL:
sudo systemctl stop mysqld
Restart MySQL:
sudo systemctl restart mysqld
Check MySQL status:
sudo systemctl status mysqld
These commands will help you maintain control over your MySQL server and troubleshoot any issues that may arise.
Creating and Managing MySQL Databases
Now that your MySQL server is set up, it’s time to create and manage databases. Log in to MySQL using your root
account:
mysql -u root -p
Enter your root
password when prompted. To create a new database, run the following command, replacing my_database
with your desired database name:
CREATE DATABASE my_database;
View a list of all databases, execute:
SHOW DATABASES;
To create a new user and grant them privileges on the newly created database, run the following commands, replacing my_user
, my_password
, and my_database
with your desired values:
CREATE USER 'my_user'@'localhost' IDENTIFIED BY 'my_password';
GRANT ALL PRIVILEGES ON my_database.* TO 'my_user'@'localhost';
FLUSH PRIVILEGES;
Now, your new user has full access to the specified database. To switch to a different database, use the USE
command:
USE my_database;
From here, you can create tables, insert data, and perform various operations within the selected database.
Conclusion
Congratulations! You’ve successfully set up a MySQL database server on Oracle Linux. With your new MySQL server, you can create and manage databases, users, and access privileges to support various applications and services.
To further enhance your Oracle Linux server, consider installing additional software such as NGINX, Apache, or Python. Additionally, explore our tutorials on how to set up RAID 1 in Ubuntu and how to install TensorFlow on Oracle Linux for more advanced configurations and optimizations.
We hope this guide has provided you with a solid foundation for setting up and managing a MySQL database server on Oracle Linux. Happy database administration!