Instalasi Database Server
Bismillahirrahmanirrahim.
Di artikel ini merupakan lanjutan dari Instalasi Web Server. Kali ini akan dilakukan instalasi Database Server. Database yang umum digunakan adalah MySQL dan MariaDB. Akhir-akhir ini, MariaDB menjadi paket default (bundling) dalam sebuah paket Server Side Scripting seperti XAMPP, namun tetap mempertahakan pendahulunya (MySQL) yang juga terus dikembangkan secara bersama-sama.
Instalasi di artikel ini mengacu pada database server MariaDB.
Instal MariaDB
Untuk menginstal MariaDB, jalankan perintah:
sudo pacman -S mysql
Seperti yang diketahui, saat ini MariaDB tersedia secara resmi sebagai implementasi default dari MySQL di Arch Linux sejak tahun 2013. Saat dimintai untuk memilih menginstal MariaDB atau Percona server, langsung saja tekan tombol enter
dan ketikkan y
dan tekan enter
lagi. Pilihan default yaitu MariaDB akan diinstal pada sistem.
[fajri@mfajri FajriCodeOS]$ sudo pacman -S mysql
[sudo] password for fajri: ##Enter user password
:: There are 2 providers available for mysql:
:: Repository extra
1) mariadb
:: Repository community
2) percona-server
Enter a number (default=1): ##Press enter to choose default
resolving dependencies...
looking for conflicting packages...
Packages (2) mariadb-clients-10.5.9-1 mariadb-10.5.9-1
Total Download Size: 30.16 MiB
Total Installed Size: 279.38 MiB
:: Proceed with installation? [Y/n] ##Enter y and press enter
Mengatur Direktori Data MariaDB
Untuk memulai service, atur direktori data MariaDB terlebih dahulu. Untuk melakukannya, jalankan perintah:
sudo mysql_install_db --user=mysql --basedir=/usr --datadir=/var/lib/mysql
Aktifkan service MariaDB
Gunakan perintah berikut untuk mengaktifkan dan menjalankan ulang service MariaDB.
sudo systemctl enable mysqld
sudo systemctl restart mysqld
Output berikut akan ditampilkan.
Installing MariaDB/MySQL system tables in '/var/lib/mysql' ...
OK
To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system
Two all-privilege accounts were created.
One is root@localhost, it has no password, but you need to
be system 'root' user to connect. Use, for example, sudo mysql
The second is mysql@localhost, it has no password either, but
you need to be the system 'mysql' user to connect.
After connecting you can set the password, if you would need to be
able to connect as any of these users with a password and without sudo
See the MariaDB Knowledgebase at https://mariadb.com/kb or the
MySQL manual for more instructions.
You can start the MariaDB daemon with:
cd '/usr' ; /usr/bin/mysqld_safe --datadir='/var/lib/mysql'
You can test the MariaDB daemon with mysql-test-run.pl
cd '/usr/mysql-test' ; perl mysql-test-run.pl
Please report any problems at https://mariadb.org/jira
The latest information about MariaDB is available at https://mariadb.org/.
You can find additional information about the MySQL part at:
https://dev.mysql.com
Consider joining MariaDB's strong and vibrant community:
https://mariadb.org/get-involved/
Untuk memeriksa apakah service MariaDB berhasil dijalankan atau belum, jalankan perintah:
sudo systemctl status mysqld
Contoh output:
● mariadb.service - MariaDB 10.5.9 database server
Loaded: loaded (/usr/lib/systemd/system/mariadb.service; disabled; ve>
Active: active (running) since Thu 2021-04-01 22:30:28 WITA; 11s ago
Docs: man:mariadbd(8)
https://mariadb.com/kb/en/library/systemd/
Process: 27163 ExecStartPre=/bin/sh -c systemctl unset-environment _WS>
Process: 27164 ExecStartPre=/bin/sh -c [ ! -e /usr/bin/galera_recovery>
Process: 27187 ExecStartPost=/bin/sh -c systemctl unset-environment _W>
Main PID: 27173 (mariadbd)
Status: "Taking your SQL requests now..."
Tasks: 14 (limit: 2219)
Memory: 83.7M
CGroup: /system.slice/mariadb.service
└─27173 /usr/bin/mariadbd
Apr 01 22:30:27 mfajri mariadbd[27173]: 2021-04-01 22:30:27 0 [Note] InnoD>
Apr 01 22:30:27 mfajri mariadbd[27173]: 2021-04-01 22:30:27 0 [Note] InnoD>
Apr 01 22:30:27 mfajri mariadbd[27173]: 2021-04-01 22:30:27 0 [Note] InnoD>
Apr 01 22:30:28 mfajri mariadbd[27173]: 2021-04-01 22:30:28 0 [Note] InnoD>
Apr 01 22:30:28 mfajri mariadbd[27173]: 2021-04-01 22:30:28 0 [Note] Serve>
Apr 01 22:30:28 mfajri mariadbd[27173]: 2021-04-01 22:30:28 0 [Note] Readi>
Apr 01 22:30:28 mfajri mariadbd[27173]: 2021-04-01 22:30:28 0 [Note] Added>
Apr 01 22:30:28 mfajri mariadbd[27173]: 2021-04-01 22:30:28 0 [Note] /usr/>
Apr 01 22:30:28 mfajri mariadbd[27173]: Version: '10.5.9-MariaDB' socket:>
Apr 01 22:30:28 mfajri systemd[1]: Started MariaDB 10.5.9 database server.
lines 1-25/25 (END)
Status Active: active (running)
pada keterangan di atas menunjukkan service mysqld
telah berhasil berjalan dengan baik.
Atur Password User Root MySQL/MariaDB
Seperti pemahaman kita bahwa sangat disarankan untuk membuat password database untuk user root. Dengan demikian, database yang ada tidak dapat diakses oleh sembarang user. Jalankan perintah:
sudo mysql_secure_installation
Contoh output:
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): #Press enter
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] #Type n and press enter
... skipping.
You already have your root account protected, so you can safely answer 'n'.
Change the root password? [Y/n] #Type y
New password: #Type your password
Re-enter new password: #Retype 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] #Press enter
... 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] #Press enter
... 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] #Press enter
- 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] #Press enter
... 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!
Mengetes Database MySQL/MariaDB
Setelah menjalankan perintah sebelumnya, database yang ada tidak dapat diakses oleh user biasa. Untuk itu, akses dataase sebagai user yang memiliki hak akses root dengan menajalankan perintah sudo su
terlebih dahulu.
$ mysql -p -u root
Enter password: #Type your database password
Jika berhasil, user akan dihadapkan pada tampilan selamat datang.
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 85
Server version: 10.5.9-MariaDB Arch Linux
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)]>
Jika langkah-langkah yang dilakukan telah sampai pada tahap ini, itu artinya database telah terinstal pada sistem.