Ads

Install mariadb 10.6 di linux ubuntu 20.04


 

Step 1: Upgrade Sistem

Seperti biasa, kita mulai dengan update dan upgrade sistem.

sudo apt update
sudo apt upgrade -y
sudo reboot

Step 2: Install Packages yang dibutuhkan

Selanjutnya install software-properties-common package

sudo apt install software-properties-common -y

Step 3: Import MariaDB GPG Key dan Tambahkan MariaDB APT Repository

Jika curl tidak bisa, kita install dulu dengan apt-get install curl, lalu lanjutkan dengan perintah dibawah secara berurutan:

curl -LsS -O https://downloads.mariadb.com/MariaDB/mariadb_repo_setup
sudo bash mariadb_repo_setup --mariadb-server-version=10.6

Kira-kira outputnya seperti dibawah ini:

[info] Checking for script prerequisites.
[info] Repository file successfully written to /etc/apt/sources.list.d/mariadb.list
[info] Adding trusted package signing keys...
[info] Running apt-get update...
[info] Done adding trusted package signing keys

Step 4: Install MariaDB 10.6 di Ubuntu 20.04|18.04

Proses install MariaDB 10.6 on Ubuntu 20.04|18.04:

sudo apt update
sudo apt install mariadb-server mariadb-client

Step 5: Secure MariaDB Installation

Setelah MariaDB terinstall, jalankan script dibawah untuk mengamankan MariaDB dengan memberikan root password.

$ sudo mariadb-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] Y
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] Y
New password: 
Re-enter new password: 
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] 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? [Y/n] Y
 ... 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] 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? [Y/n] Y
 ... 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!

Step 6: Periksa Status Service Mariadb

Service MariaDB seharusnya sudah berjalan:

$ systemctl status mariadb
 mariadb.service - MariaDB 10.6.4 database server
   Loaded: loaded (/lib/systemd/system/mariadb.service; enabled; vendor preset: enabled)
  Drop-In: /etc/systemd/system/mariadb.service.d
           └─migrated-from-my.cnf-settings.conf
   Active: active (running) since Tue 2021-10-19 11:37:25 UTC; 9s ago
     Docs: man:mariadbd(8)
           https://mariadb.com/kb/en/library/systemd/
 Main PID: 3023 (mariadbd)
   Status: "Taking your SQL requests now..."
    Tasks: 14 (limit: 4703)
   CGroup: /system.slice/mariadb.service
           └─3023 /usr/sbin/mariadbd

Oct 19 11:37:29 ubuntu /etc/mysql/debian-start[3046]: performance_schema
Oct 19 11:37:29 ubuntu /etc/mysql/debian-start[3046]: sys
Oct 19 11:37:29 ubuntu /etc/mysql/debian-start[3046]: Phase 6/7: Checking and upgrading tables
Oct 19 11:37:29 ubuntu /etc/mysql/debian-start[3046]: Processing databases
Oct 19 11:37:29 ubuntu /etc/mysql/debian-start[3046]: information_schema
Oct 19 11:37:29 ubuntu /etc/mysql/debian-start[3046]: performance_schema
Oct 19 11:37:29 ubuntu /etc/mysql/debian-start[3046]: sys
Oct 19 11:37:29 ubuntu /etc/mysql/debian-start[3046]: sys.sys_config                                     OK
Oct 19 11:37:29 ubuntu /etc/mysql/debian-start[3046]: Phase 7/7: Running 'FLUSH PRIVILEGES'
Oct 19 11:37:29 ubuntu /etc/mysql/debian-start[3046]: OK
root@ubuntu:~#

Step 7: Enable MariaDB di Start up

Jalankan perintah dibawah agar MariaDB berjalan pada saat server dinyalakan.

sudo systemctl enable mariadb

Step 8: Check MariaDB Version

Untuk memeriksa versi MariaDB yang terinstall, kita harus login terlebih dahulu dengan user root dan password yang sudah kita buat.

$ mysql -u root -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 32
Server version: 10.6.3-MariaDB-1:10.6.3+maria~focal mariadb.org binary distribution

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)]>

Dengan perintah diatas, sebetulnya kita sudah bisa mengetahui versi MariaDB, atau bisa juga kita ketikkan perintah:

MariaDB [(none)]> SELECT VERSION();
+--------------------------------------+
| VERSION()                            |
+--------------------------------------+
| 10.6.4-MariaDB-1:10.6.4+maria~bionic |
+--------------------------------------+
1 row in set (0.000 sec)

MariaDB [(none)]> QUIT
Bye

Step 9: Penggunaan Dasar MariaDB

Membuat Database

MariaDB Create Database

Perintah untuk membuat database.

#Create a new database
MariaDB [(none)]> CREATE DATABASE db1;
Query OK, 1 row affected (0.000 sec)

#If the database with the same exists
CREATE DATABASE db1;
ERROR 1007 (HY000): Can't create database 'db1'; database exists

#Create a database if already exits
MariaDB [(none)]>  CREATE OR REPLACE DATABASE db1;
Query OK, 2 rows affected (0.009 sec)

#First check if a database exists 
MariaDB [(none)]> CREATE DATABASE IF NOT EXISTS db1;
Query OK, 1 row affected, 1 warning (0.000 sec)

# Check Databases MariaDB
MariaDB [(none)]>  SHOW DATABASES;

MariaDB add user and Grant Privileges

Untuk membuat user baru dan memberikan akses ke database

#Create user mariadb
MariaDB [(none)]> CREATE USER 'myuser'@'localhost' IDENTIFIED BY 'mypassword';

#Grant all privileges to the user
MariaDB [(none)]> GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'localhost' IDENTIFIED BY 'mypassword';

#Grant privileges to a specific database
MariaDB [(none)]> GRANT ALL PRIVILEGES ON 'DB1'.* TO 'user1'@'localhost';

#Remember to refresh the privileges
MariaDB [(none)]> FLUSH privileges;

#To check user grants in MariaDB
MariaDB [(none)]> SHOW GRANTS FOR 'myuser'@'localhost';

Membuat tabel dan menambah Data MariaDB

Cara membuat tabel dan menambah data ke database.

MariaDB [(none)]> CREATE TABLE employees (id INT, name VARCHAR(20), email VARCHAR(20));
MariaDB [(none)]> INSERT INTO employees (id,name,email) VALUES(01,"lorna","lorna@example.com"

Menghapus MariaDB

Jika ingin menghapus MariaDB dari server:

sudo apt purge mariadb-server
sudo rm -rf /var/lib/mysql/

Begitulah cara menginstall MariaDB versi terbaru, yakni 10.6 di Linux Ubuntu 20.04.

SHARE

Author

I'm a Michelisian, salah seorang teknisi disebuah sekolah. Melalui Blog ini, saya menuangkan berbagai catatan tentang teknologi dan hobi.

  • Image
  • Image
  • Image
  • Image
  • Image
    Blogger Comment
    Facebook Comment

0 komentar:

Posting Komentar