This tutorial guides you through setting up MySQL, a popular open-source relational database management system, on Rocky Linux 8. MySQL is widely used for managing databases in various applications.
rocky linuxMySQL
Small
VPS
2
vCPU
4 GB
Memory
40 GB
NVMe Disk
2048 GB
Traffic
10.90€
/month
* Up to 12GB RAM, 120GB NVMe Disk Space and 1Gbit/s Network Speed
#### Prerequisites
Before you begin, ensure you have:
- A server running Rocky Linux 8
- SSH access to your server with sudo privileges
- Basic familiarity with the command line and package management on Rocky Linux
#### Step 1: Install MySQL Server
Install MySQL server using DNF package manager:
```bash
sudo dnf install mysql-server
```
#### Step 2: Start and Enable MySQL
Start the MySQL service and enable it to start on boot:
```bash
sudo systemctl start mysqld
sudo systemctl enable mysqld
```
#### Step 3: Secure MySQL Installation
Run the MySQL secure installation script to improve security:
```bash
sudo mysql_secure_installation
```
Follow the on-screen prompts to set a root password, remove anonymous users, disallow root login remotely, and remove test databases.
#### Step 4: Access MySQL
Access the MySQL shell as the root user to verify the installation:
```bash
sudo mysql -u root -p
```
Enter the root password you set during the secure installation.
#### Step 5: Optional: Create a New Database and User
Create a new database and user with appropriate privileges:
```sql
CREATE DATABASE dbname;
CREATE USER 'username'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON dbname.* TO 'username'@'localhost';
FLUSH PRIVILEGES;
```
Replace `dbname`, `username`, and `password` with your preferred database name, username, and password.
#### Conclusion
You have successfully set up MySQL on Rocky Linux 8, ready to use for your database management needs. Start creating and managing databases using MySQL on your server.
**Additional Resources:**
- **MySQL Documentation:** [https://dev.mysql.com/doc/](https://dev.mysql.com/doc/)
- **Rocky Linux Documentation:** [https://docs.rockylinux.org/](https://docs.rockylinux.org/)