MySQL merupakan salah satu service database yang bersifat opensource yang cukup populer dan banyak digunakan di berbagai infrastruktur, bahasa Query utama dari Mysql yaitu SQL. MySQL dapat di install secara multiplatfrom baik itu di windows, mac maupun GNU/Linux.
Pada artikel ini kita akan coba untuk melakukan installasi MySQL pada Redhat Linux Enterprise 8 dan bisa digunakan untuk CentOS 8.
Installasi MySQL Server
Hal pertama kita lakukan install mysql dengan perintah berikut.
1 |
sudo yum install mysql-server -y |
Selanjutnya kita aktifkan mysql agar dapat berjalan pada saat startup dan jalankan layanan.
1 2 |
sudo systemctl enable mysqld sudo systemctl start mysqld.service |
Agar service mysql dapat berjalan di jaringan yang terhubung dengan server, maka kita perlu menambahkan service pada firewall dengan perintah berikut.
1 |
sudo firewall-cmd --add-service=mysql --permanent |
Reload firewall untuk memastikan pengaturan dijalankan.
1 |
sudo firewall-cmd --reload |
Sebelum menjalankan mysql-server, kita perlu melakukan setup awal dengan menjalankan secure installation dengan perintah dibawah ini.
1 |
mysql_secure_installation |
Akan muncul Output seperti dibawah ini, kalian bisa sesuaikan seperti konfigurasi dibawah dan untuk password dapat kalian sesuaikan masing-masing.
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 65 66 67 68 69 70 |
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? # enable password validation policy or not Press y|Y for Yes, any other key for No: y 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 # select password validation policy if enabled Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 0 Please set the password for root here. # set MySQL root password New password: Re-enter new password: # confirmation of the password you input 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 or not 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 or not 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 or not 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 or not Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y Success. All done! |
Setelah setup selesai, maka selanjutnya kita coba masuk kedalam console mysql dengan perintah berikut ini.
1 |
sudo mysql -u root -p |
Jika berhasil masuk, maka hasilnya akan seperti diawah.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
[vagrant@rhel8 ~]$ sudo mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 10 Server version: 8.0.32 Source distribution Copyright (c) 2000, 2023, Oracle and/or its affiliates. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> |
Menambah User baru MySQL
Pada bagian ini kita akan coba untuk membuat sebuah user baru di Mysql yang memiliki akses penuh seperti root user yang secara default terinstall. Pertama pastikan kamu sudah masuk kedalam console MySQL
1 |
sudo mysql -u root -p |
Selanjutnya tambahkan user mysql baru, disini saya akan membuat user dengan nama warrior dengan password @warrior098765.
1 |
CREATE USER 'warrior'@'localhost' IDENTIFIED BY '@warrior098765'; |
Berikan permission pada user tersebut dengan mengizinkan seluruh akses.
1 |
GRANT ALL PRIVILEGES ON *.* TO 'warrior'@'localhost' WITH GRANT OPTION; |
Reload statement perubahan yang sudah dilakukan agar tersimpan langsung dalam sistem.
1 |
FLUSH PRIVILEGES; |
Keluar dari console dengan menggunakan perintah exit, lalu coba kembali login dengan user baru.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
[vagrant@rhel8 ~]$ sudo mysql -u warrior -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 11 Server version: 8.0.32 Source distribution Copyright (c) 2000, 2023, Oracle and/or its affiliates. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> |
Kita ujicoba hak akses dengan melihat database yang ada di mysql dengan perintah berikut.
1 2 3 4 5 6 7 8 9 10 11 12 |
mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | sys | +--------------------+ 4 rows in set (0.02 sec) mysql> |
Apabila sudah muncul seperti diatas maka bisa dinyatakan pembuatan user dengan full akses sudah berhasil dilakukan.
Penutup
Installasi mysql server pada Redhat 8 tidak begitu sulit, karena tidak jauh berbeda dengan installasi pada sistem operasi gnu/linux lain pada umumnya. Hanya saja perlu diperhatikan yaitu penambahan service pada firewall agar mysql dapat diakses dari jaringan yang sama.
Referensi
- https://www.server-world.info/en/note?os=CentOS_8&p=mysql8&f=1