In this tutorial, learn how to **install MySQL on Ubuntu 24.04 LTS** step by step. MySQL is one of the most popular relational database management systems, essential for managing structured data efficiently. Whether you're setting up a database for web development, data analysis, or application hosting, this guide will walk you through the complete installation and basic configuration process.

---

### What You’ll Learn:
1. How to install MySQL Server on Ubuntu 24.04 LTS.
2. Setting up MySQL for the first time.
3. Verifying the installation.

---

### Steps to Install MySQL on Ubuntu 24.04 LTS

#### 1. **Update System Packages**
Before starting, ensure your system packages are up-to-date:
```bash
sudo apt update && sudo apt upgrade -y
```

#### 2. **Install MySQL Server**
Install MySQL using the APT package manager:
```bash
sudo apt install mysql-server -y
```
This will install the latest MySQL server version available in Ubuntu's official repositories.

#### 3. **Secure MySQL Installation**
After installation, run the secure installation script to improve MySQL security:
```bash
sudo mysql_secure_installation
```
- You’ll be prompted to set a root password.
- Follow the on-screen instructions to remove test databases, disable remote root login, and apply other security measures.

#### 4. **Start and Enable MySQL Service**
Ensure the MySQL service is running and set to start automatically on boot:
```bash
sudo systemctl start mysql
sudo systemctl enable mysql
```

#### 5. **Log In to MySQL**
Log in as the root user to verify the installation:
```bash
sudo mysql -u root -p
```
Enter the root password you set earlier.

#### 6. **Test the Installation**
Run the following command to check the MySQL version and confirm the installation:
```bash
mysql --version
```

---
To change the MySQL root password, follow these steps:

---

### **Method 1: Using MySQL Command Line**

1. **Log in as the root user:**
```bash
mysql -u root -p
```
Enter the current root password when prompted.

2. **Change the root password:**
```sql
ALTER USER 'root'@'localhost' IDENTIFIED BY 'NewPassword';
FLUSH PRIVILEGES;
```
Replace `NewPassword` with your desired password.

3. **Exit the MySQL prompt:**
```sql
EXIT;
```

### Optional Steps:

#### Create a New Database:
```sql
CREATE DATABASE example_db;
```

#### Create a New User:
```sql
CREATE USER 'example_user'@'localhost' IDENTIFIED BY 'password';
```

#### Grant Privileges:
```sql
GRANT ALL PRIVILEGES ON example_db.* TO 'example_user'@'localhost';
```
Flush privileges to apply changes:
```sql
FLUSH PRIVILEGES;
```

---

### Why Choose MySQL?
- **Widely Used**: Perfect for web development and large-scale data applications.
- **Flexible**: Works seamlessly with many programming languages and frameworks.
- **Community Support**: Extensive documentation and support forums.

By following these steps, you’ll have MySQL installed and configured on Ubuntu 24.04 LTS, ready to manage your databases efficiently. Don't forget to subscribe for more Linux tutorials!

#MySQL #Ubuntu24 #LinuxTutorial #DatabaseManagement #WebDevelopment #MySQLUbuntu #OpenSourceTools #TechGuide #UbuntuLTS