MariaDB package repository setup script<\/a>.<\/p>\n\n\n\nThe script allows you to choose the version of MariaDB you want to set the APT repositories for.<\/p>\n\n\n\n
For example, to install APT repository for MariaDB 11, then execute the command below;<\/p>\n\n\n\n
curl -LsS https:\/\/r.mariadb.com\/downloads\/mariadb_repo_setup | \\\nsudo bash -s -- --mariadb-server-version=\"mariadb-11.0\"<\/code><\/pre>\n\n\n\nSample script output;<\/p>\n\n\n\n
\n# [info] Checking for script prerequisites.\n# [info] MariaDB Server version 11.0 is valid\n# [info] Repository file successfully written to \/etc\/apt\/sources.list.d\/mariadb.list\n# [info] Adding trusted package signing keys...\n# [info] Running apt-get update...\n# [info] Done adding trusted package signing keys\n<\/code><\/pre>\n\n\n\nInstalling MariaDB 11 on Debian 11\/Debian 10;<\/h4>\n\n\n\n
You should now be able to install MariaDB 11 by running the command below;<\/p>\n\n\n\n
apt install mariadb-server<\/code><\/pre>\n\n\n\nVerify the MariaDB installed version<\/h4>\n\n\n\n
MariaDB 11 deprecates the use of mysql<\/code><\/strong> command line tool and replaces it with mariadb<\/code>.<\/p>\n\n\n\nAs much as you can still be able to use mysql command, you will get some deprecation warnings.<\/p>\n\n\n\n
To check the version of installed MariaDB, run the command below;<\/p>\n\n\n\n
mariadb -V<\/code><\/pre>\n\n\n\nmariadb from 11.0.1-MariaDB, client 15.2 for debian-linux-gnu (x86_64) using readline EditLine wrapper<\/code><\/pre>\n\n\n\nRunning MariaDB 11 on Debian 11\/Debian 10<\/h4>\n\n\n\n
Upon installation, MariaDB is started and enabled to run on system boot;<\/p>\n\n\n\n
systemctl status mariadb<\/code><\/pre>\n\n\n\n\n\u25cf mariadb.service - MariaDB 11.0.1 database server\n Loaded: loaded (\/lib\/systemd\/system\/mariadb.service; enabled; vendor preset: enabled)\n Drop-In: \/etc\/systemd\/system\/mariadb.service.d\n \u2514\u2500migrated-from-my.cnf-settings.conf\n Active: active (running) since Wed 2023-05-03 09:11:48 EAT; 9min ago\n Docs: man:mariadbd(8)\n https:\/\/mariadb.com\/kb\/en\/library\/systemd\/\n Process: 13468 ExecStartPre=\/usr\/bin\/install -m 755 -o mysql -g root -d \/var\/run\/mysqld (code=exited, status=0\/SUCCESS)\n Process: 13469 ExecStartPre=\/bin\/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0\/SUCCESS)\n Process: 13471 ExecStartPre=\/bin\/sh -c [ ! -e \/usr\/bin\/galera_recovery ] && VAR= || VAR=`cd \/usr\/bin\/..; \/usr\/bin\/galera_recovery`; [ $? -eq 0 ] && systemctl set-e>\n Process: 13516 ExecStartPost=\/bin\/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0\/SUCCESS)\n Process: 13518 ExecStartPost=\/etc\/mysql\/debian-start (code=exited, status=0\/SUCCESS)\n Main PID: 13500 (mariadbd)\n Status: \"Taking your SQL requests now...\"\n Tasks: 8 (limit: 2341)\n Memory: 205.6M\n CPU: 502ms\n CGroup: \/system.slice\/mariadb.service\n \u2514\u250013500 \/usr\/sbin\/mariadbd\n\nMay 03 09:11:47 debian11 mariadbd[13500]: 2023-05-03 9:11:47 0 [Note] Plugin 'wsrep-provider' is disabled.\nMay 03 09:11:47 debian11 mariadbd[13500]: 2023-05-03 9:11:47 0 [Note] InnoDB: Loading buffer pool(s) from \/var\/lib\/mysql\/ib_buffer_pool\nMay 03 09:11:48 debian11 mariadbd[13500]: 2023-05-03 9:11:48 0 [Note] Server socket created on IP: '127.0.0.1'.\nMay 03 09:11:48 debian11 mariadbd[13500]: 2023-05-03 9:11:48 0 [Note] InnoDB: Buffer pool(s) load completed at 230503 9:11:48\nMay 03 09:11:48 debian11 mariadbd[13500]: 2023-05-03 9:11:48 0 [Note] \/usr\/sbin\/mariadbd: ready for connections.\nMay 03 09:11:48 debian11 mariadbd[13500]: Version: '11.0.1-MariaDB-1:11.0.1+maria~deb11' socket: '\/run\/mysqld\/mysqld.sock' port: 3306 mariadb.org binary distribution\nMay 03 09:11:48 debian11 systemd[1]: Started MariaDB 11.0.1 database server.\nMay 03 09:11:48 debian11 \/etc\/mysql\/debian-start[13520]: Upgrading MySQL tables if necessary.\nMay 03 09:11:48 debian11 \/etc\/mysql\/debian-start[13531]: Checking for insecure root accounts.\nMay 03 09:11:48 debian11 \/etc\/mysql\/debian-start[13535]: Triggering myisam-recover for all MyISAM tables and aria-recover for all Aria tables\n<\/code><\/pre>\n\n\n\nYou can manage the service via systemctl command.<\/p>\n\n\n\n
For example, to start MariaDB service;<\/p>\n\n\n\n
systemctl start mariadb<\/code><\/pre>\n\n\n\nFor example, to restart MariaDB service;<\/p>\n\n\n\n
systemctl restart mariadb<\/code><\/pre>\n\n\n\nTo stop the service;<\/p>\n\n\n\n
systemctl stop mariadb<\/code><\/pre>\n\n\n\nDisable the service from running on system boot;<\/p>\n\n\n\n
systemctl disable mariadb<\/code><\/pre>\n\n\n\nSecuring MariaDB 11<\/h3>\n\n\n\n
MariaDB comes with a default security script, mariadb-secure-installation<\/code><\/strong> that is used to improve the security of MariaDB installation by:<\/p>\n\n\n\n\n- Setting the password for root accounts (if need be).<\/li>\n\n\n\n
- Disabling remote root login to the databases.<\/li>\n\n\n\n
- Removing anonymous-user accounts.<\/li>\n\n\n\n
- Removing the test database, which by default can be accessed by anonymous users.<\/li>\n<\/ul>\n\n\n\n
Simply run the command below to launch the script.<\/p>\n\n\n\n
mariadb-secure-installation<\/code><\/pre>\n\n\n\nMariaDB Authentication<\/h3>\n\n\n\n
The new installations of MariaDB have two secure accounts are created during the installation.<\/p>\n\n\n\n
The accounts are root@localhost<\/code><\/strong> and mysql@localhost<\/strong><\/code>.<\/p>\n\n\n\nBoth accounts uses either of the unix_socket<\/code><\/strong> and the mysql_native_password<\/code><\/strong> authentication plugins.<\/p>\n\n\n\nunix_socket<\/strong><\/code> authentication plugin allows a system root<\/code> user or a user with sudo rights<\/strong><\/code> to login as root@locahost<\/strong><\/code> to MariaDB database without a password.<\/p>\n\n\n\nWith unix_socket<\/strong><\/code> authentication plugin, while being a root user, you can simply login by running either of the commands below;<\/p>\n\n\n\nmariadb<\/code><\/pre>\n\n\n\nor<\/p>\n\n\n\n
mariadb -u root<\/code><\/pre>\n\n\n\nEven if you run, mariadb -u root -p<\/strong><\/code>, and press ENTER for blank password, you will still login.<\/p>\n\n\n\nAs a user with sudo rights, prefix the commands above with sudo<\/strong><\/code>.<\/p>\n\n\n\nFor example, you can login as mysql user;<\/p>\n\n\n\n
sudo -u mysql mariadb<\/code><\/pre>\n\n\n\nEnable MariaDB password Authentication<\/h3>\n\n\n\n
With the two privileged accounts, root@localhost<\/code><\/strong> and mysql@localhost<\/code><\/strong>, anyone with access to it can login to MariaDB.<\/p>\n\n\n\nIt is not recommended to leave such user accounts with no password and all privileges, as this can pose a significant security risk to your database.<\/p>\n\n\n\n
The two accounts above uses mysql_native_password<\/code> plugin by default;<\/p>\n\n\n\nmariadb<\/code><\/pre>\n\n\n\nselect User,Host,plugin from mysql.user;<\/code><\/pre>\n\n\n\n\n+-------------+-----------+-----------------------+\n| User | Host | plugin |\n+-------------+-----------+-----------------------+\n| mariadb.sys | localhost | mysql_native_password |\n| root | localhost | mysql_native_password |\n| mysql | localhost | mysql_native_password |<\/strong>\n+-------------+-----------+-----------------------+\n3 rows in set (0.002 sec)\n\nMariaDB [(none)]>\n<\/code><\/pre>\n\n\n\nThe mysql_native_password<\/code> plugin is used as a failover for the unix_socket<\/code> plugin. Even if you have setup a password using MariaDB secure installation script, you can still login as those accounts without a password.<\/p>\n\n\n\nshow grants for root@localhost;<\/code><\/pre>\n\n\n\n\n+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------+\n| Grants for root@localhost |\n+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------+\n| GRANT ALL PRIVILEGES ON *.* TO `root`@`localhost` IDENTIFIED VIA mysql_native_password USING '*9C6C35530EE4427B07D2FA4F9E119C3915D18940' OR unix_socket WITH GRANT OPTION |\n| GRANT PROXY ON ''@'%' TO 'root'@'localhost' WITH GRANT OPTION |\n+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------+\n2 rows in set (0.000 sec)\n\nMariaDB [(none)]>\n<\/code><\/pre>\n\n\n\nshow grants for mysql@localhost;<\/code><\/pre>\n\n\n\n\n+------------------------------------------------------------------------------------------------------------------------------------------+\n| Grants for mysql@localhost |\n+------------------------------------------------------------------------------------------------------------------------------------------+\n| GRANT ALL PRIVILEGES ON *.* TO `mysql`@`localhost` IDENTIFIED VIA mysql_native_password USING 'invalid' OR unix_socket WITH GRANT OPTION |\n+------------------------------------------------------------------------------------------------------------------------------------------+\n1 row in set (0.000 sec)\n\nMariaDB [(none)]>\n<\/code><\/pre>\n\n\n\nAs you can see above, we had already set the password for root user using the mysql_secure_installation command. But mysql user account has invalid password.<\/p>\n\n\n\n
Thus, enable password authentication.<\/p>\n\n\n\n
ALTER USER root@localhost identified by 'myStr0nP@ssW0rd';<\/code><\/pre>\n\n\n\nALTER USER mysql@localhost identified by 'myStr0nP@ssW0rd2';<\/code><\/pre>\n\n\n\nflush privileges;\nquit<\/code><\/pre>\n\n\n\nThis re-enables the MariaDB password authentication and hence, you can now login as non root or non sudo user.<\/p>\n\n\n\n
mariadb<\/code><\/pre>\n\n\n\nOr;<\/p>\n\n\n\n
sudo -u mysql mariadb<\/code><\/pre>\n\n\n\nSample output;<\/p>\n\n\n\n
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)<\/code><\/pre>\n\n\n\nProvide a password to be able to login;<\/p>\n\n\n\n
mariadb -u root -p<\/code><\/pre>\n\n\n\n\nEnter password: \nWelcome to the MariaDB monitor. Commands end with ; or \\g.\nYour MariaDB connection id is 35\nServer version: 11.0.1-MariaDB-1:11.0.1+maria~deb10 mariadb.org binary distribution\n\nCopyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.\n\nType 'help;' or '\\h' for help. Type '\\c' to clear the current input statement.\n\nMariaDB [(none)]>\n<\/code><\/pre>\n\n\n\nSet Native Password Authentication Method as Default<\/h4>\n\n\n\n
When you set the password above, it completely disables unix_socke<\/code>t authentication plugin and instead use the msqyl_native_password<\/code> authentication method;<\/p>\n\n\n\nshow grants for root@localhost;<\/code><\/pre>\n\n\n\n\n+----------------------------------------------------------------------------------------------------------------------------------------+\n| Grants for root@localhost |\n+----------------------------------------------------------------------------------------------------------------------------------------+\n| GRANT ALL PRIVILEGES ON *.* TO `root`@`localhost` IDENTIFIED BY PASSWORD '*73E1DDB4DA8B34D3080B082A8DFC863A56285DD4' WITH GRANT OPTION |\n| GRANT PROXY ON ''@'%' TO 'root'@'localhost' WITH GRANT OPTION |\n+----------------------------------------------------------------------------------------------------------------------------------------+\n2 rows in set (0.000 sec)\n\nMariaDB [(none)]>\n<\/code><\/pre>\n\n\n\nshow grants for mysql@localhost;<\/code><\/pre>\n\n\n\n\n+-----------------------------------------------------------------------------------------------------------------------------------------+\n| Grants for mysql@localhost |\n+-----------------------------------------------------------------------------------------------------------------------------------------+\n| GRANT ALL PRIVILEGES ON *.* TO `mysql`@`localhost` IDENTIFIED BY PASSWORD '*4C8C1832BBF14A360C2F70EA14CBD912AE0AF280' WITH GRANT OPTION |\n+-----------------------------------------------------------------------------------------------------------------------------------------+\n1 row in set (0.000 sec)\n\nMariaDB [(none)]>\n<\/code><\/pre>\n\n\n\nThat marks the end of our guide on how to installing MariaDB 11 on Debian 11\/Debian 10.<\/p>\n\n\n\n
Other Tutorials<\/h3>\n\n\n\n
You can check our other MySQL\/MariaDB related tutorials<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"Follow through this guide to learn how to install MariaDB 11 on Debian 11\/Debian 10. \u201cMariaDB 11 is the new major release series of MariaDB. It<\/p>\n","protected":false},"author":10,"featured_media":16350,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"rank_math_lock_modified_date":false,"footnotes":""},"categories":[121,299,928],"tags":[6587,6586,6585,6584,6588],"class_list":["post-16346","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-howtos","category-database","category-mariadb","tag-debian-11-mariadb-10","tag-debian-11-mariadb-11","tag-install-mariadb-11-on-debian","tag-install-mariadb-11-on-linux","tag-mariadb-11-install","generate-columns","tablet-grid-50","mobile-grid-100","grid-parent","grid-50","resize-featured-image"],"_links":{"self":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/16346"}],"collection":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/users\/10"}],"replies":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/comments?post=16346"}],"version-history":[{"count":6,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/16346\/revisions"}],"predecessor-version":[{"id":20756,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/16346\/revisions\/20756"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/media\/16350"}],"wp:attachment":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/media?parent=16346"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/categories?post=16346"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/tags?post=16346"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}