BLOG POSTS
How to Install the Latest MySQL on Ubuntu 24

How to Install the Latest MySQL on Ubuntu 24

MySQL remains one of the most popular relational database management systems worldwide, and keeping it updated on your Ubuntu server is crucial for security, performance, and access to the latest features. Ubuntu 24.04 LTS brings exciting changes to how we manage database installations, and installing the latest MySQL version ensures you get the newest performance optimizations, security patches, and developer-friendly features. This guide will walk you through multiple installation methods, troubleshoot common issues, and share best practices for running MySQL in production environments.

Why Upgrade to the Latest MySQL on Ubuntu 24

MySQL 8.0.x series delivers significant improvements over older versions, including enhanced JSON support, window functions, common table expressions, and improved performance schema. Ubuntu 24.04 ships with MySQL 8.0 in its repositories, but the version might lag behind the official MySQL releases by several months.

Here’s what you gain with the latest MySQL version:

  • Performance improvements with up to 2x faster read/write operations
  • Enhanced security features including improved password validation
  • Better JSON document handling with new operators and functions
  • Invisible indexes for testing query performance without dropping indexes
  • Role-based access control for more granular permissions
  • Atomic DDL operations preventing partial schema changes

Installation Methods Comparison

Method Latest Version Ease of Updates Configuration Control Best For
Ubuntu Repository Sometimes outdated Automatic with apt Standard Simple setups
MySQL APT Repository Always latest Automatic with apt Full control Production servers
Docker Container Always latest Manual container updates Containerized Development/microservices
Source Compilation Always latest Manual Complete control Custom optimizations

Method 1: Installing MySQL via Official MySQL APT Repository

The MySQL APT repository provides the most reliable way to get the latest MySQL version and maintain it with regular updates. This method is recommended for production environments.

Step 1: Download and Install MySQL APT Config

wget https://dev.mysql.com/get/mysql-apt-config_0.8.29-1_all.deb
sudo dpkg -i mysql-apt-config_0.8.29-1_all.deb

During the installation, you’ll see a configuration screen. Select “MySQL Server & Cluster (Currently selected: mysql-8.0)” and choose “Ok” to proceed.

Step 2: Update Package Index

sudo apt update

Step 3: Install MySQL Server

sudo apt install mysql-server

During installation, you’ll be prompted to set a root password. Choose a strong password and remember it for later configuration steps.

Step 4: Verify Installation

mysql --version
sudo systemctl status mysql

You should see output similar to:

mysql  Ver 8.0.35-0ubuntu0.24.04.1 for Linux on x86_64
● mysql.service - MySQL Community Server
   Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
   Active: active (running)

Method 2: Using Ubuntu’s Default Repository

For development environments or when you need a quick MySQL installation, Ubuntu’s default repository works perfectly fine, though it might not have the absolute latest version.

sudo apt update
sudo apt install mysql-server
sudo systemctl start mysql
sudo systemctl enable mysql

Method 3: Docker Installation for Development

Docker provides an isolated, reproducible MySQL environment perfect for development work or when you need multiple MySQL versions.

# Pull the latest MySQL image
docker pull mysql:latest

# Run MySQL container
docker run --name mysql-server \
  -e MYSQL_ROOT_PASSWORD=your_strong_password \
  -p 3306:3306 \
  -d mysql:latest

# Connect to MySQL
docker exec -it mysql-server mysql -uroot -p

Post-Installation Security Configuration

Regardless of your installation method, running the security script is essential for production deployments:

sudo mysql_secure_installation

This script helps you:

  • Set password validation policy
  • Remove anonymous users
  • Disable root login remotely
  • Remove test database
  • Reload privilege tables

Essential Configuration Tweaks

After installation, optimize your MySQL configuration by editing /etc/mysql/mysql.conf.d/mysqld.cnf:

[mysqld]
# Performance tuning
innodb_buffer_pool_size = 1G
innodb_log_file_size = 256M
max_connections = 200
query_cache_size = 128M

# Security settings
bind-address = 127.0.0.1
skip-name-resolve

# Character set
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci

Restart MySQL after configuration changes:

sudo systemctl restart mysql

Common Issues and Troubleshooting

Issue: MySQL Service Won’t Start

Check the error logs and service status:

sudo systemctl status mysql
sudo journalctl -u mysql.service
sudo tail -f /var/log/mysql/error.log

Common solutions:

  • Check disk space: df -h
  • Verify file permissions: sudo chown -R mysql:mysql /var/lib/mysql
  • Reset configuration if corrupted

Issue: Can’t Connect to MySQL Server

Verify MySQL is running and check connection settings:

sudo netstat -tlnp | grep :3306
mysql -u root -p -h localhost

Issue: Authentication Plugin Problems

MySQL 8.0 uses caching_sha2_password by default. For compatibility with older clients:

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'your_password';
FLUSH PRIVILEGES;

Performance Benchmarking

Test your MySQL installation performance using the built-in benchmark tools:

# Install MySQL test suite
sudo apt install mysql-server-8.0

# Run basic performance test
mysqlslap --user=root --password --host=localhost \
  --concurrency=20 --iterations=1000 \
  --create-schema=test_db \
  --query="SELECT * FROM performance_schema.global_status LIMIT 10"

Real-World Use Cases and Examples

Setting Up a Development Database

# Create development database and user
mysql -u root -p

CREATE DATABASE app_development;
CREATE USER 'developer'@'localhost' IDENTIFIED BY 'dev_password';
GRANT ALL PRIVILEGES ON app_development.* TO 'developer'@'localhost';
FLUSH PRIVILEGES;

Configuring Remote Access for Team Development

# Edit MySQL config
sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf

# Change bind-address to:
bind-address = 0.0.0.0

# Create remote user
CREATE USER 'remote_dev'@'%' IDENTIFIED BY 'secure_password';
GRANT SELECT, INSERT, UPDATE, DELETE ON app_development.* TO 'remote_dev'@'%';

# Configure firewall
sudo ufw allow 3306

Best Practices for Production Environments

When running MySQL on production servers, especially on VPS or dedicated servers, follow these practices:

  • Enable binary logging for point-in-time recovery
  • Set up automated backups using mysqldump or Percona XtraBackup
  • Monitor slow query log and optimize problematic queries
  • Implement proper SSL/TLS encryption for client connections
  • Use connection pooling to manage database connections efficiently
  • Regular security updates and patch management

Backup Strategy Implementation

# Create backup script
#!/bin/bash
BACKUP_DIR="/var/backups/mysql"
DATE=$(date +%Y%m%d_%H%M%S)

mysqldump --single-transaction --routines --triggers \
  --all-databases > $BACKUP_DIR/mysql_backup_$DATE.sql

# Compress backup
gzip $BACKUP_DIR/mysql_backup_$DATE.sql

# Remove backups older than 7 days
find $BACKUP_DIR -name "*.sql.gz" -mtime +7 -delete

Monitoring and Maintenance

Set up basic monitoring to track MySQL performance:

# Check MySQL status
mysql -u root -p -e "SHOW GLOBAL STATUS LIKE 'Threads_connected';"
mysql -u root -p -e "SHOW PROCESSLIST;"

# Monitor slow queries
mysql -u root -p -e "SELECT * FROM mysql.slow_log ORDER BY start_time DESC LIMIT 10;"

Enable performance schema for detailed monitoring:

# Add to my.cnf
[mysqld]
performance_schema = ON
performance-schema-instrument='stage/%=ON'
performance-schema-consumer-events-stages-current=ON

Integration with Popular Development Stacks

MySQL 8.0 integrates seamlessly with modern development frameworks. Here’s how different stacks connect:

  • LAMP Stack: Apache + PHP 8.x + MySQL 8.0 provides excellent performance for web applications
  • Node.js: Use mysql2 package for connection pooling and prepared statements
  • Python Django: Configure database backend with mysqlclient driver
  • Docker Compose: Perfect for microservices architecture with container orchestration

The latest MySQL on Ubuntu 24.04 delivers robust performance, enhanced security, and modern features that support contemporary application development. Whether you choose the official MySQL repository for cutting-edge features or Ubuntu’s stable packages for reliability, proper configuration and maintenance ensure optimal database performance for your applications.

For additional resources, check the official MySQL 8.0 Reference Manual and Ubuntu Server MySQL documentation for comprehensive guides and troubleshooting information.



This article incorporates information and material from various online sources. We acknowledge and appreciate the work of all original authors, publishers, and websites. While every effort has been made to appropriately credit the source material, any unintentional oversight or omission does not constitute a copyright infringement. All trademarks, logos, and images mentioned are the property of their respective owners. If you believe that any content used in this article infringes upon your copyright, please contact us immediately for review and prompt action.

This article is intended for informational and educational purposes only and does not infringe on the rights of the copyright owners. If any copyrighted material has been used without proper credit or in violation of copyright laws, it is unintentional and we will rectify it promptly upon notification. Please note that the republishing, redistribution, or reproduction of part or all of the contents in any form is prohibited without express written permission from the author and website owner. For permissions or further inquiries, please contact us.

Leave a reply

Your email address will not be published. Required fields are marked