How To Install MySQL on Rocky Linux 10
MySQL stands as one of the most widely adopted open-source relational database management systems in the world. Its robust performance, reliability, and extensive feature set make it the backbone of countless web applications, enterprise systems, and data-driven platforms. When paired with Rocky Linux 10, a stable and secure enterprise-grade operating system, MySQL creates a powerful foundation for database operations.
Rocky Linux 10 provides an excellent environment for hosting MySQL servers, offering long-term support, enhanced security features, and enterprise-level stability. This comprehensive guide will walk you through multiple installation methods, security configurations, and optimization techniques to get MySQL running efficiently on your Rocky Linux 10 system.
Whether you’re a system administrator managing production servers, a developer setting up a local development environment, or a DevOps engineer implementing database infrastructure, this tutorial covers everything you need to know. You’ll learn two primary installation approaches, essential security practices, user management, remote access configuration, and troubleshooting techniques that will ensure your MySQL deployment is both secure and performant.
Prerequisites and System Requirements
Before diving into the MySQL installation process, ensure your Rocky Linux 10 system meets the necessary requirements and prerequisites.
Hardware Requirements
MySQL’s performance heavily depends on adequate system resources. For basic installations and development environments, allocate at least 1GB of RAM and 10GB of available disk space. Production environments require more substantial resources, with a minimum of 4GB RAM and sufficient storage based on your expected database size and growth projections.
CPU requirements vary depending on workload, but modern multi-core processors provide optimal performance for concurrent database operations. Consider SSD storage for improved I/O performance, especially for write-heavy applications and large datasets.
Software Requirements
Your Rocky Linux 10 system must have a complete base installation with network connectivity. Administrative privileges through sudo access are essential for installing packages, configuring services, and managing system settings.
Basic command-line familiarity will help you navigate the installation process more efficiently. Ensure your system packages are current by running regular updates, as outdated packages can cause compatibility issues during MySQL installation.
Network connectivity is crucial for downloading packages from repositories, whether using the default Rocky Linux repositories or official MySQL sources. Verify your DNS resolution and package manager functionality before proceeding with the installation.
Understanding MySQL Versions and Repository Options
Rocky Linux 10 offers multiple pathways for MySQL installation, each with distinct advantages and considerations.
Default Rocky Linux 10 Repository vs Official MySQL Repository
The default Rocky Linux repositories include MySQL packages that undergo extensive testing for compatibility with the operating system. These packages typically represent stable, well-tested versions that integrate seamlessly with other system components. However, they may not always include the latest MySQL features and improvements.
Official MySQL repositories provide access to the most recent MySQL releases, including cutting-edge features, performance enhancements, and security updates. These repositories offer more frequent updates and direct support from Oracle’s MySQL development team. The trade-off involves potentially encountering compatibility issues with other system packages or requiring additional configuration steps.
Version compatibility becomes crucial when planning long-term database deployments. Consider your application requirements, support lifecycle expectations, and integration needs when choosing between repository sources.
Choosing the Right Installation Method
Default repositories work best for stable production environments where consistency and predictability outweigh access to the latest features. This approach minimizes potential conflicts and simplifies system maintenance.
Official MySQL repositories suit environments requiring specific MySQL versions, latest features, or direct vendor support. Development environments and applications leveraging newer MySQL capabilities benefit from this approach.
Long-term maintenance considerations include update frequency, security patching, and compatibility with existing system components. Evaluate your organization’s policies and technical requirements before making this decision.
Method 1: Installing MySQL from Default Rocky Linux Repository
The default repository installation provides the most straightforward path to getting MySQL running on Rocky Linux 10.
Step-by-Step Installation Process
Begin by updating your system packages to ensure compatibility and security. Open a terminal and execute:
sudo dnf update -y
This command refreshes package information and installs available updates. The process may take several minutes depending on your system’s current state and available updates.
Next, install the MySQL server package using the DNF package manager:
sudo dnf install mysql-server -y
DNF will automatically resolve dependencies and install required packages. You’ll see output indicating package downloads, dependency resolution, and installation progress. The installation typically includes the MySQL server daemon, client tools, and essential configuration files.
Verify the installation success by checking the installed MySQL version:
mysql --version
This command should display version information confirming successful installation.
Starting and Enabling MySQL Service
Rocky Linux 10 uses systemd for service management. Start the MySQL service with:
sudo systemctl start mysqld
Enable automatic startup during system boot:
sudo systemctl enable mysqld
Check the service status to ensure proper operation:
sudo systemctl status mysqld
The output should show “active (running)” status with recent log entries. If you encounter issues, examine the service logs using:
sudo journalctl -u mysqld
These logs provide detailed information about service startup problems, configuration errors, or permission issues.
Method 2: Installing MySQL from Official MySQL Repository
Installing from official MySQL repositories gives you access to the latest versions and features directly from Oracle.
Downloading and Adding MySQL Repository
Navigate to the MySQL official repository download page or use wget to download the repository package directly:
wget https://dev.mysql.com/get/mysql80-community-release-el9-1.noarch.rpm
This command downloads the MySQL repository configuration package. The package contains repository definitions and GPG keys for package verification.
Install the repository package using RPM:
sudo rpm -Uvh mysql80-community-release-el9-1.noarch.rpm
The installation adds MySQL repository configurations to your system, enabling access to official MySQL packages.
Installing Latest MySQL Version
Update your package index to include the newly added MySQL repository:
sudo dnf update -y
Install MySQL server from the official repository:
sudo dnf install mysql-community-server -y
This command installs the latest MySQL Community Server version available in the official repository. The installation process may prompt you to accept GPG keys for package verification.
Handle any package conflicts by reviewing dependency information and selecting appropriate packages. If conflicts arise, consider removing conflicting packages or using specific version specifications.
Verify successful installation:
mysql --version
Start and enable the MySQL service as described in the previous method.
Securing Your MySQL Installation
MySQL security configuration represents a critical step in any installation process.
Running mysql_secure_installation Script
MySQL includes a security script that addresses common security vulnerabilities. Execute the script:
sudo mysql_secure_installation
The script guides you through several security-related decisions. Initially, you may encounter a prompt about the validate password component. This optional component enforces password strength requirements for MySQL users.
Choose whether to enable password validation based on your security requirements. Production environments typically benefit from password validation, while development systems may prioritize convenience.
The script presents several security prompts:
First, set a strong root password. Avoid common passwords, dictionary words, or predictable patterns. Use a combination of uppercase letters, lowercase letters, numbers, and special characters.
Password Policy Configuration
MySQL offers three password validation levels: LOW, MEDIUM, and STRONG. LOW policy requires passwords with at least 8 characters. MEDIUM policy adds requirements for mixed case, numbers, and special characters. STRONG policy includes additional checks against dictionary words and common patterns.
Production environments should implement MEDIUM or STRONG policies to prevent weak passwords. Development environments may use LOW policy for convenience while maintaining reasonable security.
Create root passwords that exceed minimum requirements regardless of policy level. Strong passwords significantly reduce unauthorized access risks.
Additional Security Steps
The security script prompts for several additional security measures:
- Remove anonymous users that allow connections without authentication. Anonymous users create significant security vulnerabilities and should be removed in all environments.
- Disable remote root login to prevent network-based attacks against the root account. Create separate administrative accounts for remote management instead of enabling remote root access.
- Remove the test database installed by default. Test databases may contain sample data or relaxed permissions that create security risks.
- Reload privilege tables to ensure all security changes take effect immediately. This step commits all security modifications to the MySQL grant system.
Initial MySQL Configuration and Testing
After installation and security configuration, verify MySQL functionality and perform basic configuration tasks.
Connecting to MySQL Server
Connect to your MySQL server using the command-line client:
mysql -u root -p
Enter the root password you configured during the security process. Successful connection displays the MySQL prompt:
mysql>
This prompt indicates you’re connected to the MySQL server and ready to execute SQL commands. The MySQL client provides comprehensive help through the help
command and supports command history for convenience.
Understanding basic MySQL navigation improves your administrative efficiency. Use the quit
or exit
commands to leave the MySQL console.
Basic Database Operations
Test your MySQL installation by creating a sample database:
CREATE DATABASE test_db;
View existing databases to confirm creation:
SHOW DATABASES;
This command displays all databases accessible to your current user, including system databases like information_schema
, mysql
, performance_schema
, and sys
.
Switch to your new database:
USE test_db;
Create a simple table to verify full functionality:
CREATE TABLE sample_table (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(50),
created_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
These basic operations confirm your MySQL installation is functioning correctly and ready for production use.
Creating MySQL Users and Managing Permissions
Proper user management forms the foundation of MySQL security and access control.
Creating New MySQL Users
Create dedicated users instead of using the root account for applications and regular operations. The MySQL user creation syntax follows this pattern:
CREATE USER 'username'@'hostname' IDENTIFIED BY 'password';
For local applications, create users for localhost access:
CREATE USER 'app_user'@'localhost' IDENTIFIED BY 'SecurePassword123!';
For remote applications, specify the client hostname or IP address:
CREATE USER 'remote_user'@'192.168.1.100' IDENTIFIED BY 'AnotherSecurePassword456!';
Use the wildcard ‘%’ cautiously for any-host access, as it creates potential security risks:
CREATE USER 'api_user'@'%' IDENTIFIED BY 'VerySecurePassword789!';
Username conventions should reflect the user’s purpose and access requirements. Consider prefixes like ‘app_’, ‘web_’, or ‘admin_’ to categorize users by function.
Granting and Managing Privileges
MySQL’s privilege system operates on multiple levels: global, database, table, and column. Grant only necessary privileges following the principle of least privilege.
Grant database-specific privileges for application users:
GRANT SELECT, INSERT, UPDATE, DELETE ON app_database.* TO 'app_user'@'localhost';
For administrative users requiring broader access:
GRANT ALL PRIVILEGES ON *.* TO 'admin_user'@'localhost' WITH GRANT OPTION;
The WITH GRANT OPTION
clause allows users to grant privileges to other users. Use this option sparingly and only for trusted administrative accounts.
View user privileges with:
SHOW GRANTS FOR 'username'@'hostname';
Revoke privileges when access requirements change:
REVOKE INSERT, UPDATE ON app_database.* FROM 'app_user'@'localhost';
Always flush privileges after making changes:
FLUSH PRIVILEGES;
Configuring MySQL for Remote Access
Remote access configuration enables applications and users to connect to MySQL from other systems.
Modifying MySQL Configuration
Edit the MySQL configuration file to allow remote connections:
sudo vim /etc/my.cnf
Locate or add the bind-address
directive in the [mysqld]
section:
[mysqld]
bind-address = 0.0.0.0
Setting bind-address to 0.0.0.0 allows connections from any IP address. For enhanced security, specify specific IP addresses or network ranges:
bind-address = 192.168.1.0/24
Configure the MySQL port if using non-standard settings:
port = 3306
Save the configuration file and restart MySQL to apply changes:
sudo systemctl restart mysqld
Verify the service restarted successfully:
sudo systemctl status mysqld
Firewall Configuration
Rocky Linux 10 uses firewalld for firewall management. Open the MySQL port for external connections:
sudo firewall-cmd --permanent --add-service=mysql
Alternatively, open the port directly:
sudo firewall-cmd --permanent --add-port=3306/tcp
For specific network access, create targeted rules:
sudo firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="192.168.1.0/24" service name="mysql" accept'
Reload firewall rules to activate changes:
sudo firewall-cmd --reload
Test remote connectivity from another system:
mysql -h your_server_ip -u username -p
Security considerations for remote access include using encrypted connections, implementing strong authentication, and regularly monitoring access logs for suspicious activity.
Performance Optimization and Best Practices
Optimizing MySQL performance ensures efficient database operations and resource utilization.
Initial Performance Tuning
Key configuration parameters significantly impact MySQL performance. The InnoDB buffer pool size represents the most important memory setting:
innodb_buffer_pool_size = 2G
Set this value to 70-80% of available RAM for dedicated database servers. Smaller values work for systems running multiple services.
Configure connection limits based on expected concurrent users:
max_connections = 200
max_connect_errors = 1000000
Query cache configuration can improve read performance for repetitive queries:
query_cache_type = 1
query_cache_size = 256M
However, query cache may reduce performance in write-heavy environments due to cache invalidation overhead.
Monitoring and Maintenance
Use mysqladmin for basic monitoring and server status information:
mysqladmin -u root -p status
Monitor key performance metrics:
mysqladmin -u root -p extended-status
MySQL log files provide valuable information for troubleshooting and optimization. The error log location varies by installation method:
sudo tail -f /var/log/mysqld.log
Enable slow query logging to identify performance bottlenecks:
slow_query_log = 1
slow_query_log_file = /var/log/mysql/slow.log
long_query_time = 2
Regular maintenance tasks include optimizing tables, analyzing query performance, and monitoring disk space usage. Implement automated backup strategies to protect against data loss.
Troubleshooting Common Installation Issues
Understanding common problems and their solutions helps resolve installation and configuration issues quickly.
Service Start Problems
MySQL service failures often result from configuration errors, permission issues, or port conflicts. Check the service status first:
sudo systemctl status mysqld
Examine detailed error messages in the system journal:
sudo journalctl -u mysqld -f
Common startup issues include:
Permission problems with data directory ownership. Fix with:
sudo chown -R mysql:mysql /var/lib/mysql
Port conflicts when other services use port 3306. Identify conflicting processes:
sudo netstat -tlnp | grep 3306
Configuration file syntax errors prevent service startup. Validate configuration syntax and correct any errors before restarting the service.
Connection and Authentication Issues
Authentication failures typically involve incorrect passwords, user privileges, or network connectivity problems.
Test local connections first to isolate network issues:
mysql -u root -p -h localhost
For remote connection problems, verify:
- Firewall rules allow MySQL traffic
- MySQL configuration permits remote connections
- User accounts have proper host specifications
- Network connectivity between client and server
Password authentication failures may result from expired passwords or account lockouts. Reset user passwords when necessary:
ALTER USER 'username'@'hostname' IDENTIFIED BY 'NewPassword';
User privilege issues require reviewing and adjusting grant tables. Verify user permissions match application requirements.
Advanced Configuration Options
Advanced MySQL configurations optimize performance and enhance security for production environments.
MySQL Server Configuration Tuning
Fine-tune memory allocation based on server resources and workload characteristics. The InnoDB log file size affects recovery time and write performance:
innodb_log_file_size = 256M
innodb_log_buffer_size = 64M
Thread handling optimization improves concurrent connection performance:
thread_cache_size = 50
table_open_cache = 4000
Configure appropriate timeout values for your application requirements:
wait_timeout = 600
interactive_timeout = 600
Setting Up MySQL for Production
Production environments require comprehensive security hardening beyond basic installation. Implement SSL/TLS encryption for client connections:
ssl-ca = /path/to/ca-cert.pem
ssl-cert = /path/to/server-cert.pem
ssl-key = /path/to/server-key.pem
Establish robust backup strategies including automated daily backups, point-in-time recovery capabilities, and regular restore testing. Monitor disk space, connection counts, and query performance continuously.
Consider implementing MySQL replication for high availability and load distribution. Master-slave configurations provide read scalability, while master-master setups enable write distribution with proper conflict resolution.
Congratulations! You have successfully installed MySQL server. Thanks for using this tutorial for installing the MySQL database on your Rocky Linux 9 system. For additional help or useful information, we recommend you check the official MySQL website.