Configurare MySQL APT Repository
Incepand cu versiunea 9 a sistemului de operare Debian Linux (Stretch), serverul de baza de date MySQL nu mai este sistemul de gestiune a bazelor de date implicit; acest rol a fost alocat unei alte distributii, MariaDB. Cu toate acestea, serverul MySQL poate fi instalat pe baza arhivelor oficiale MySQL (MySQL APT Repository).
Pentru a putea instala distributia oficiala MySQL, in prima faza este necesara descarcarea pachetului mysql-apt-config_0.8.11-1_all.deb folosind comanda wget. Pachetul poate fi descarcat de la urmatoarea adresa https://dev.mysql.com/downloads/repo/apt/.
wget http://repo.mysql.com/mysql-apt-config_0.8.11-1_all.deb
--2019-01-12 22:41:29-- http://repo.mysql.com/mysql-apt-config_0.8.11-1_all.deb Resolving repo.mysql.com (repo.mysql.com)... 92.122.199.8 Connecting to repo.mysql.com (repo.mysql.com)|92.122.199.8|:80... connected. HTTP request sent, awaiting response... 200 OK Length: 35420 (35K) [application/x-debian-package] Saving to: ‘mysql-apt-config_0.8.11-1_all.deb’ mysql-apt-config_0.8.11-1_al 100%[=============================================>] 34.59K --.-KB/s in 0.001s 2019-01-12 22:41:29 (30.8 MB/s) - ‘mysql-apt-config_0.8.11-1_all.deb’ saved [35420/35420]
Dupa descarcarea pachetului mysql-apt-config_0.8.11-1_all.deb, putem lista toate fisierele din directorul curent pentru a verifica daca operatia s-a realizat cu succes.
ls -lha
total 36K -rw-r--r-- 1 airman airman 35K Nov 27 08:11 mysql-apt-config_0.8.11-1_all.deb
Cel mai simplu, instalarea pachetului descarcat anterior se poate realiza prin intermediul managerului de pachete software dpkg, pentru care trebuie precizate doua valori: optiunea -i necesara derularii unui proces de instalare, respectiv numele pachetului. Utilitarul dpkg poate fi utilizat pentru a instala, sterge sau verifica pachete software (.deb).
sudo dpkg -i mysql-apt-config_0.8.11-1_all.deb
Pe parcursul instalarii pachetului este necesara precizarea versiunii serverului MySQL care se doreste a fi disponibila pentru instalare. Am avut in vedere in cadrul acestui tutorial instalarea ultimei versiuni stabile a serverului MySQL.
Instalare MySQL Community Server
Inainte de instalarea serverului MySQL, pe masina care ruleaza Debian 9 este necesara actualizarea listei de pachete software.
sudo apt-get update
Dupa actualizarea listei, se poate trece la instalarea serverului MySQL si a clientului MySQL (clientul linie de comanda).
sudo apt-get install mysql-server
Pe durata instalarii este necesara stabilirea parolei pentru administratorul serverului MySQL (utilizatorul root), dar si a plugin-ului ce urmeaza a fi utilizat in procesul de autentificare. Inainte de a stabili plugin-ul pentru autentificare verificati daca acesta este suportat in aplicatii.
Verificarea statusului server-ului MySQL
Dupa instalare, serverul MySQL este implicit pornit. Verificarea starii pentru sistemul MySQL se poate realiza cu urmatoarea comanda:
sudo service mysql status
mysql.service - MySQL Community Server Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled) Active: active (running) since Sun 2019-01-13 00:10:11 UTC; 23s ago Docs: man:mysqld(8) http://dev.mysql.com/doc/refman/en/using-systemd.html Process: 3708 ExecStartPre=/usr/share/mysql-8.0/mysql-systemd-start pre (code=exited, status=0/SUCCESS) Main PID: 3743 (mysqld) Status: "SERVER_OPERATING" Tasks: 38 (limit: 4915) CGroup: /system.slice/mysql.service └─3743 /usr/sbin/mysqld Jan 13 00:10:10 virtualcampus-ro systemd[1]: Starting MySQL Community Server… Jan 13 00:10:11 virtualcampus-ro systemd[1]: Started MySQL Community Server.
Oprirea serverului MySQL se face folosind urmatoarea comanda:
sudo service mysql stop
Pentru (re)pornirea sistemului este necesara urmatoarea comanda:
sudo service mysql start
Securizarea server-ului MySQL
O modalitatea simpla de imbunatatire a securitatii sistemelor de gestiune a bazelor de date de tip MySQL este disponibila prin intermediul comenzii mysql_secure_installation.
Prin rularea acestei comenzi, se desfasoara un proces de securizare care implica: actualizarea metodologiei de stabilire a parolelor, modificarea parolei pentru utilizatorul de tip administrator sistem (root), stergerea utilizatorilor de tip anonim (anonymous), dezactivarea conectarii la distanta pentru utilizatorul de tip administrator sistem (root), stergerea bazei de date de test.
sudo mysql_secure_installation
Securing the MySQL server deployment. Enter password for user root: 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: Using existing password for root. Change the password for root ? ((Press y|Y for Yes, any other key for No) : ... skipping. 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!
Accesarea server-ului MySQL folosind clientul linie de comanda
Dupa instalarea MySQL Community Server, conectarea din terminal, pe baza clientului linie de comanda, se poate realiza astfel:
sudo mysql -h localhost -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.13 MySQL Community Server - GPL Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved. 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> SELECT version(); +-----------+ | version() | +-----------+ | 8.0.13 | +-----------+ 1 row in set (0.05 sec) mysql> \q Bye