> For the complete documentation index, see [llms.txt](https://supportx.gitbook.io/buku-mantra-and-sihir/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://supportx.gitbook.io/buku-mantra-and-sihir/trik-sihir/ubuntu/install-mysql-5.7.-on-ubuntu-22.04-24.04-dan-25.04.md).

# Install MySQL 5.7.\* on Ubuntu 22.04, 24.04 dan 25.04

Download library dibawah ini dah ekstrak

{% embed url="<https://drive.google.com/file/d/1ETZY06KTK2tCvSOQQwGBUS42hBYDT0f0/view?usp=sharing>" %}
library mysql on ubuntu
{% endembed %}

Masuk ke folder yang sesui dengan versi ubuntu lu dan install

```bash
// folder ubuntu22 untuk ubuntu 22.04
sudo dpkg -i libtinfo22.deb

// folder ubuntu24 untuk ubuntu 24.04
sudo dpkg -i libaio24.deb
sudo dpkg -i libtinfo24.deb
sudo dpkg -i libncurses24.deb

// folder ubuntu25 untuk ubuntu 25.04
sudo dpkg -i libaio25.deb
sudo dpkg -i libtinfo25.deb
sudo dpkg -i libncurses25.deb
```

### **Langkah #1: Tambahkan Repositori APT MySQL**

#### **Perbarui Paket Sistem:**

```bash
sudo apt update
```

#### **Install `wget`:**

```bash
// ubuntu 22.04, 24.04
sudo apt install wget -y

// ubuntu 25.04
sudo apt install wget gnupg -y
```

#### **Unduh repositori MySQL:**

```bash
wget https://dev.mysql.com/get/mysql-apt-config_0.8.12-1_all.deb
```

#### **Instal repositori MySQL:**

```bash
sudo dpkg -i mysql-apt-config_0.8.12-1_all.deb
```

* Saat muncul prompt, pilih **Ubuntu Bionic**, lalu klik **OK**.
* Di prompt berikutnya, versi default adalah MySQL 8.0. Pilih opsi pertama (ganti ke MySQL 5.7) lalu klik **OK**.
* Di prompt selanjutnya, pilih **MySQL 5.7 Server**, lalu klik **OK**.
* Di prompt terakhir, MySQL 5.7 akan terpilih secara default. Pilih opsi terakhir "OK", lalu klik **OK**.

***

### **Langkah #2: Perbarui Repositori MySQL**

#### **Perbarui ulang sistem:**

```bash
sudo apt-get update
```

#### **Cek versi MySQL yang tersedia:**

```bash
sudo apt-cache policy mysql-server
```

***

### **Langkah #3: Instal MySQL 5.7 di Ubuntu 22.04 LTS**

#### **Tambahkan kunci repositori:**

<pre class="language-bash"><code class="lang-bash"><strong>// ubuntu 22.04, 24.04
</strong><strong>sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys B7B3B788A8D3785C
</strong><strong>
</strong><strong>// ubuntu 25.04
</strong>sudo gpg --keyserver keyserver.ubuntu.com --recv-keys B7B3B788A8D3785C
sudo gpg --export B7B3B788A8D3785C | sudo gpg --dearmor -o /etc/apt/trusted.gpg.d/mysql.gpg

sudo apt update
</code></pre>

#### **Install MySQL 5.7 client dan server:**

```bash
sudo apt install -f mysql-client=5.7* mysql-community-server=5.7* mysql-server=5.7*
```

* Tekan `y` untuk memulai instalasi.
* Masukkan dan konfirmasi ulang **password root** saat diminta.

***

### **Langkah #4: Amankan Instalasi MySQL 5.7**

#### **Jalankan perintah keamanan:**

```bash
sudo mysql_secure_installation
```

* Masukkan password root yang telah dibuat.
* Pilih `y` untuk mengaktifkan plugin VALIDATE PASSWORD.
* Pilih tingkat validasi (0 = Rendah, 1 = Sedang, 2 = Tinggi), misalnya: `1`
* Pilih `no` untuk **tidak mengganti password root** (jika sudah yakin).
* Pilih `y` untuk:
  * Menghapus user anonim
  * Menolak login root dari jarak jauh
  * Menghapus database `test`
  * Reload tabel hak akses

***

### **Langkah #5: Cek Versi MySQL**

#### **Login ke MySQL:**

```bash
mysql -u root -p
```

#### **Cek versi:**

```sql
SELECT VERSION();
```

***

### **Langkah #6: Buat User MySQL Baru**

#### **Perintah membuat user:**

```sql
CREATE USER 'sap'@'%' IDENTIFIED BY 'password';
grant all privileges on *.* to 'sap'@'%' with grant option;
flush privileges;
```

***

### **Langkah #7: Aktifkan Akses Remote ke MySQL**

#### **Buka file konfigurasi:**

```bash
sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf
```

#### **Ubah baris `bind-address`:**

Ubah dari:

```bash
bind-address = 127.0.0.1
```

Menjadi:

```bash
bind-address = 0.0.0.0
```

#### **Simpan dan restart MySQL:**

```bash
sudo systemctl restart mysql
```

***

### **Perintah Tambahan:**

* **Restart MySQL:**

```bash
sudo systemctl restart mysql
```

* **Hentikan MySQL:**

```bash
sudo systemctl stop mysql
```

* **Cek status MySQL:**

```bash
sudo systemctl status mysql
```
