Cara Instalasi Database MariaDB di CentOS 8
MariaDB adalah sistem manajemen database relasional yang dikembangkan dari MySQL. MariaDB dikembangkan oleh komunitas pengembang yang sebelumnya berkontribusi untuk database MySQL.
Mengapa pengembang MySQL membangun MariaDB? Salah satu alasannya, MySQL telah diakuisisi oleh Oracle sehingga menyebabkan MySQL menjadi produk yang berlisensi proprietary. Dengan diakuisisinya MySQL oleh Oracle, maka pengembangan MySQL pun sudah tidak leluasa lagi. Hal ini yang menyebabkan pengembang MySQL sebelumnya mulai membangun MariaDB.
Untuk awal mula penomoran versi, MariaDB mengikuti skema penomoran MySQL yakni 5.5. Setelah versi 5.5, pengembang MariaDB memutuskan untuk ‘lompat jauh’ dengan memberi versi terbaru mereka dengan penomoran 10. Tidak hanya penomoran versinya saja, fitur-fitur major pun dibangun dalam MariaDB. Saat ini versi terbaru MariaDB yang stabil adalah MariaDB 10.5.5, sebagai berikut
Di CentOS 8 secara default repository yang tersedia untuk MariaDB versi 10.3, jika kita ingin install latest version yang stabil di versi 10.5.5 Anda perlu menambahkan repository MariaDB terlebih dahulu caranya sebagai berikut:
Klik pada link berikut: https://downloads.mariadb.org/mariadb/repositories/ untuk melihat dan mengambil repository nya
Buat repository MariaDB
1
2
[root@tutorial ~]#
[root@tutorial ~]# vim /etc/yum.repos.d/MariaDB.repo
Isi repository diatas
1
2
3
4
5
6
7
8
# MariaDB 10.5 CentOS repository list - created 2020-08-21 23:57 UTC
# http://downloads.mariadb.org/mariadb/repositories/
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.5/centos8-amd64
module_hotfixes=1
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
Jika sudah silakan simpan dan jalankan perintah berikut, untuk instalasi MariaDB
1
2
[root@tutorial ~]#
[root@tutorial ~]# dnf install MariaDB-server -y
Apabila instalasi sudah selesai, silakan di start dan pastikan statusnya running
1
2
3
4
5
[root@tutorial ~]#
[root@tutorial ~]# systemctl start mariadb
[root@tutorial ~]# systemctl status mariadb |grep Active
Active: active (running) since Sat 2020-08-22 00:06:04 UTC; 42s ago
[root@tutorial ~]#
Untuk melihat versi MariaDB gunakan perintah berikut
1
2
3
4
[root@tutorial ~]#
[root@tutorial ~]# mariadb --version
mariadb Ver 15.1 Distrib 10.5.5-MariaDB, for Linux (x86_64) using readline 5.1
[root@tutorial ~]#
Saat ini MariaDB sudah terinstall, jika kita menjalankan perintah mariadb Anda akan langsung masuk ke shell MariaDB
Selanjutnya kita akan mengatur password untuk login ke sisi MariaDB nya, mari kita atur password root MariaDB dengan cara menjalankan perintah berikut
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
71
[root@tutorial ~]# mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MariaDB to secure it, we'll need the current
password for the root user. If you've just installed MariaDB, and
haven't set the root password yet, you should just press enter here.
Enter current password for root (enter for none):
OK, successfully used password, moving on...
Setting the root password or using the unix_socket ensures that nobody
can log into the MariaDB root user without the proper authorisation.
You already have your root account protected, so you can safely answer 'n'.
Switch to unix_socket authentication [Y/n]
Enabled successfully!
Reloading privilege tables..
... Success!
You already have your root account protected, so you can safely answer 'n'.
Change the root password? [Y/n]
New password: #INPUT PASSWORD MARIADB
Re-enter new password: #KONFIRMASI PASSWORD ROOT MARIADB DIATAS
Password updated successfully!
Reloading privilege tables..
... Success!
By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB 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? [Y/n]
... 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? [Y/n]
... Success!
By default, MariaDB 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? [Y/n]
- 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? [Y/n]
... Success!
Cleaning up...
All done! If you've completed all of the above steps, your MariaDB
installation should now be secure.
Thanks for using MariaDB!
[root@tutorial ~]#
Jika sudah silakan coba kembali untuk login ke mariadb menggunakan user root seperti berikut
1
2
3
4
5
6
7
8
9
10
11
12
[root@tutorial ~]#
[root@tutorial ~]# mariadb -u root -p
Enter password: #ISI Password Mariadb
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 17
Server version: 10.5.5-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]>
Kamia akan berikut contoh membuat database dan user serta assign user ke database, dengan skema sebagai berikut _ testdb _ adalah nama database, _ testuser _ adalah user/pengguna, _ password _ adalah kata sandi user/pengguna, Anda harus mengubah kata sandi dengan kata sandi yang aman atau sesuai keinginan:
1
2
3
4
5
6
7
8
9
10
11
12
13
MariaDB [(none)]>
MariaDB [(none)]> create database testdb;
Query OK, 1 row affected (0.002 sec)
MariaDB [(none)]> create user 'testuser'@localhost identified by 'password';
Query OK, 0 rows affected (0.004 sec)
MariaDB [(none)]> grant all on testdb.* to 'testuser' identified by 'password';
Query OK, 0 rows affected (0.006 sec)
MariaDB [(none)]> quit
Bye
[root@tutorial ~]#
Sekarang login menggunakan user _ testuser _
1
2
3
4
5
6
7
8
9
10
11
12
[root@tutorial ~]#
[root@tutorial ~]# mysql -u testuser -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 18
Server version: 10.5.5-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]>
Sekarang kita akan mencoba membuat sample tabel (customer) di dalam database yang suda kita buat sebelumnya
1
2
3
4
5
6
MariaDB [(none)]> use testdb;
Database changed
MariaDB [testdb]> CREATE TABLE customers (customer_id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, first_name TEXT, last_name TEXT);
Query OK, 0 rows affected (0.079 sec)
MariaDB [testdb]>
Untuk melihat tabel berikut perintah nya
1
2
3
4
5
6
7
8
9
MariaDB [testdb]> show tables;
+------------------+
| Tables_in_testdb |
+------------------+
| customers |
+------------------+
1 row in set (0.001 sec)
MariaDB [testdb]>
Tambahkan data ke tabel customer
1
2
3
4
MariaDB [testdb]> INSERT INTO customers (first_name, last_name) VALUES ('John', 'Doe');
Query OK, 1 row affected (0.007 sec)
MariaDB [testdb]>
Lihat data tabel customer
1
2
3
4
5
6
7
8
9
MariaDB [testdb]> SELECT * FROM customers;
+-------------+------------+-----------+
| customer_id | first_name | last_name |
+-------------+------------+-----------+
| 1 | John | Doe |
+-------------+------------+-----------+
1 row in set (0.001 sec)
MariaDB [testdb]>
Untuk keluar dari MariaDB bisa menggunakan quit atau exit
1
2
3
MariaDB [testdb]> quit
Bye
[root@tutorial ~]#
Selamat mencoba 😄