Pengenalan
Dalam era digital saat ini, manajemen data menjadi hal yang krusial bagi banyak bisnis dan organisasi. Sebagai salah satu sistem manajemen basis data yang paling populer, MySQL menawarkan fitur-fitur andal dan fleksibilitas yang dibutuhkan untuk mengelola data secara efektif.
MySQL adalah sistem manajemen basis data relasional (RDBMS) yang bersifat open source dan populer di seluruh dunia. MySQL digunakan untuk menyimpan dan mengelola data dalam jumlah besar dengan cara yang terstruktur dan efisien.
Persyaratan
- Akses ke server yang menggunakan AlmaLinux 8.
- Hak akses root atau pengguna dengan izin sudo untuk menjalankan perintah.
- Koneksi internet yang stabil untuk mengunduh paket yang diperlukan.
Instalasi MySQL 8.0
Ketika menginstall MySQL 8.0, Anda memiliki dua pilihan metode – melalui AppStream bawaan server atau menggunakan repository resmi dari MySQL. Namun, keputusan ini harus disesuaikan dengan kebutuhan Anda.
Jika Anda memilih untuk menggunakan repository AppStream, perlu dipertimbangkan bahwa terkadang terdapat keterlambatan dalam memperbarui versi. Sebagai contoh, situs web resmi MySQL mungkin sudah merilis versi 8.0.37, namun di repository AppStream masih pada versi 8.0.36.
Akan tetapi, jika aplikasi Anda tidak memerlukan fitur-fitur signifikan dari perbedaan versi tersebut, maka penggunaan repository AppStream mungkin bukan masalah besar.
Dalam tutorial ini Anda akan mempelajarai cara install MySQL melalui dua cara yaitu AppStream dan repository resmi dari MySQL agar mendapatkan update terbaru. Pada artikel ini kami menggunakan resource Cloud VPS SSD Storage dengan spesifikasi Compute SSD – 1.
Install MySQL Melalui AppStream
Update server untuk memperbarui paket yang diperlukan agar tetap optimal
1 |
dnf update -y |
Cek module MySQL pada AppStream menggunakan perintah berikut
1 |
dnf module list mysql |
Contoh outputnya
1 2 3 4 5 |
AlmaLinux 8 - AppStream Name Stream Profiles Summary mysql 8.0 [d][x] client, server [d] MySQL Module Hint: [d]efault, [e]nabled, [x]disabled, [i]nstalled |
Terlihat pada output diatas bahwa MySQL 8 pada repository AppStream belum diaktifkan, silahkan aktifkan menggunakan perintah berikut
1 |
dnf module enable mysql -y |
Apabila repository sudah aktif maka hasilnya seperti berikut ini
1 2 3 4 5 |
AlmaLinux 8 - AppStream Name Stream Profiles Summary mysql 8.0 [d][e] client, server [d] MySQL Module Hint: [d]efault, [e]nabled, [x]disabled, [i]nstalled |
Apabila repository sudah aktif, jalankan perintah berikut untuk menginstall MySQL 8
1 |
dnf module install mysql:8.0 |
Berikut adalah output dari paket yang akan diinstall pada server
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
======================================================================================================================================================================================================== Package Architecture Version Repository Size ======================================================================================================================================================================================================== Installing group/module packages: mysql-server x86_64 8.0.36-1.module_el8.9.0+3735+82bd6c11 appstream 32 M Installing dependencies: libicu x86_64 60.3-2.el8_1 baseos 8.8 M mariadb-connector-c-config noarch 3.1.11-2.el8_3 appstream 14 k mecab x86_64 0.996-2.module_el8.6.0+3340+d764b636 appstream 392 k mysql x86_64 8.0.36-1.module_el8.9.0+3735+82bd6c11 appstream 14 M mysql-common x86_64 8.0.36-1.module_el8.9.0+3735+82bd6c11 appstream 136 k mysql-errmsg x86_64 8.0.36-1.module_el8.9.0+3735+82bd6c11 appstream 640 k protobuf-lite x86_64 3.5.0-15.el8 appstream 148 k Installing module profiles: mysql/server Transaction Summary ======================================================================================================================================================================================================== Install 8 Packages |
Aktifkan service MySQL agar dapat berjalan otomatis saat server direboot
1 |
systemctl enable --now mysqld |
Pastikan outputnya seperti berikut
1 2 3 4 5 6 7 8 9 10 11 12 |
● mysqld.service - MySQL 8.0 database server Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled) Active: active (running) since Sat 2024-06-15 16:39:14 UTC; 18s ago Process: 4056 ExecStartPost=/usr/libexec/mysql-check-upgrade (code=exited, status=0/SUCCESS) Process: 3935 ExecStartPre=/usr/libexec/mysql-prepare-db-dir mysqld.service (code=exited, status=0/SUCCESS) Process: 3911 ExecStartPre=/usr/libexec/mysql-check-socket (code=exited, status=0/SUCCESS) Main PID: 4012 (mysqld) Status: "Server is operational" Tasks: 38 (limit: 5635) Memory: 480.0M CGroup: /system.slice/mysqld.service └─4012 /usr/libexec/mysqld --basedir=/usr |
Cek versi MySQL saat ini
1 |
mysql --version |
Berikut contoh outputnya
1 |
mysql Ver 8.0.36 for Linux on x86_64 (Source distribution) |
Konfigurasi Keamanan MySQL
Langkah berikutnya adalah mengamankan MySQL karena saat ini Anda bisa login menggunakan blank password dengan mengetik perintah mysql sudah bisa login tanpa autentikasi. Oleh karena itu kita akan melakukan konfigurasi keamanan dasar pada MySQL
1 |
mysql_secure_installation |
Berikut adalah contoh outputnya
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
Securing the MySQL server deployment. Connecting to MySQL using a blank password. VALIDATE PASSWORD COMPONENT can be used to test passwords and improve security. It checks the strength of password and allows the users to set only those passwords which are secure enough. Would you like to setup VALIDATE PASSWORD component? Press y|Y for Yes, any other key for No: Yes There are three levels of password validation policy: LOW Length >= 8 MEDIUM Length >= 8, numeric, mixed case, and special characters STRONG Length >= 8, numeric, mixed case, special characters and dictionary file Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 0 Please set the password for root here. New password: Re-enter new password: Estimated strength of the password: 50 Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : Y By default, a MySQL installation has an anonymous user, allowing anyone to log into MySQL without having to have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment. Remove anonymous users? (Press y|Y for Yes, any other key for No) : Y Success. Normally, root should only be allowed to connect from 'localhost'. This ensures that someone cannot guess at the root password from the network. Disallow root login remotely? (Press y|Y for Yes, any other key for No) : Y Success. By default, MySQL comes with a database named 'test' that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment. Remove test database and access to it? (Press y|Y for Yes, any other key for No) : Y - Dropping test database... Success. - Removing privileges on test database... Success. Reloading the privilege tables will ensure that all changes made so far will take effect immediately. Reload privilege tables now? (Press y|Y for Yes, any other key for No) : Y Success. All done! |
Jalankan perintah berikut untuk login ke MySQL
1 |
mysql -u root -p |
Saat ini Anda sudah berhasil melakukan instalasi melalui repository AppStream dan melakukan konfigurasi keamanan dasar pada MySQL 8. Anda dapat melakukan administrasi seperti membuat database, tabel, dan lain sebagainya.
Install MySQL Melalui Repository
Update server untuk memperbarui paket yang diperlukan agar tetap optimal
1 |
dnf update -y |
Buat file untuk repository
1 |
nano /etc/yum.repos.d/mysql-community.repo |
Kemudian isikan dengan script berikut
1 2 3 4 5 6 |
[mysql80-community] name=MySQL 8.0 Community Server baseurl=http://repo.mysql.com/yum/mysql-8.0-community/el/8/$basearch/ enabled=1 gpgcheck=1 gpgkey=https://repo.mysql.com/RPM-GPG-KEY-mysql-2023 |
Matikan module MySQL dari server agar dapat menginstall versi MySQL 8
1 |
dnf module disable mysql |
Selanjutnya jalankan perintah berikut untuk menginstall MySQL8. Perintah tersebut akan menginstal paket untuk server MySQL (mysql-community-server) dan juga paket untuk komponen yang diperlukan untuk menjalankan server, termasuk paket untuk klien (mysql-community-client).
1 |
dnf install mysql-community-server -y |
Berikut adalah output dari paket yang akan diinstall pada server
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
======================================================================================================================================================================================================== Package Architecture Version Repository Size ======================================================================================================================================================================================================== Installing: mysql-community-server x86_64 8.0.37-1.el8 mysql80-community 65 M Installing dependencies: mysql-community-client x86_64 8.0.37-1.el8 mysql80-community 16 M mysql-community-client-plugins x86_64 8.0.37-1.el8 mysql80-community 3.6 M mysql-community-common x86_64 8.0.37-1.el8 mysql80-community 668 k mysql-community-icu-data-files x86_64 8.0.37-1.el8 mysql80-community 2.2 M mysql-community-libs x86_64 8.0.37-1.el8 mysql80-community 1.5 M Transaction Summary ======================================================================================================================================================================================================== Install 6 Packages |
Aktifkan service MySQL agar dapat berjalan otomatis saat server direboot
1 |
systemctl enable --now mysqld |
Cek status MySQL menggunakan perintah berikut
1 |
systemctl status mysqld |
Pastikan outputnya seperti berikut
1 2 3 4 5 6 7 8 9 10 11 12 |
● mysqld.service - MySQL Server Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled) Active: active (running) since Sat 2024-06-15 17:40:49 UTC; 21s ago Docs: man:mysqld(8) http://dev.mysql.com/doc/refman/en/using-systemd.html Process: 1926 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS) Main PID: 1998 (mysqld) Status: "Server is operational" Tasks: 38 (limit: 5635) Memory: 467.1M CGroup: /system.slice/mysqld.service └─1998 /usr/sbin/mysql |
Cek versi MySQL saat ini
1 |
mysql --version |
Berikut contoh outputnya
1 |
mysql Ver 8.0.37 for Linux on x86_64 (MySQL Community Server - GPL) |
Secara otomatis MySQL akan membuat password secara acak untuk keamanan, silahkan jalankan perintah ini untuk melanjutkan ke tahap berikutnya
1 |
cat /var/log/mysqld.log | grep "temporary password" |
Contoh outputnya seperti berikut
1 |
2024-06-15T17:40:39.436232Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: Wwq1)WpsgjGa |
Konfigurasi Keamanan MySQL
Selanjutnya kita akan melakukan konfigurasi keamanan dasar. Jalankan perintah berikut untuk memulai proses setup keamanan pada MySQL. Masukkan password yang sudah diambil dari log, contohnya password kami untuk root sebelumnya adalah Wwq1)WpsgjGa
1 |
mysql_secure_installation |
Berikut contoh output ketika menjalankan perintah diatas
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
Securing the MySQL server deployment. Enter password for user root: The existing password for the user account root has expired. Please set a new password. New password: Re-enter new password: The 'validate_password' component is installed on the server. The subsequent steps will run with the existing configuration of the component. Using existing password for root. Estimated strength of the password: 100 Change the password for root ? ((Press y|Y for Yes, any other key for No) : Y New password: Re-enter new password: Estimated strength of the password: 100 Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : Y By default, a MySQL installation has an anonymous user, allowing anyone to log into MySQL without having to have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment. Remove anonymous users? (Press y|Y for Yes, any other key for No) : Y Success. Normally, root should only be allowed to connect from 'localhost'. This ensures that someone cannot guess at the root password from the network. Disallow root login remotely? (Press y|Y for Yes, any other key for No) : Y Success. By default, MySQL comes with a database named 'test' that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment. Remove test database and access to it? (Press y|Y for Yes, any other key for No) : Y - Dropping test database... Success. - Removing privileges on test database... Success. Reloading the privilege tables will ensure that all changes made so far will take effect immediately. Reload privilege tables now? (Press y|Y for Yes, any other key for No) : Y Success. All done! |
Jalankan perintah berikut untuk login ke MySQL
1 |
mysql -u root -p |
Kesimpulan
Dengan mengikuti panduan instalasi MySQL 8.0 pada server AlmaLinux 8 yang telah kita bahas, Anda dapat dengan mudah mengintegrasikan MySQL ke dalam infrastruktur IT Anda. MySQL 8.0 menawarkan peningkatan kinerja, keamanan, dan fitur-fitur baru yang akan membantu Anda mengelola data Anda dengan lebih efisien. Jika Anda mengalami kendala, jangan ragu untuk mencari bantuan dari sumber-sumber yang terpercaya dan membaca dokumentasi resmi MySQL. Selamat mencoba!