------
Install MariaDB on Ubuntu 24.04, 22.04, or 20.04
mariadb --versionmysql -V# apt install dirmngr ca-certificates software-properties-common apt-transport-https curl -y** Importing the GPG Key# curl -fsSL http://mirror.mariadb.org/PublicKey_v2 | sudo gpg --dearmor | sudo tee /usr/share/keyrings/mariadb.gpg > /dev/null** MariaDB Version RepositoryMariaDB 11.4 (Long-term release) End-of-life date: February 2030.# echo "deb [arch=amd64,arm64,ppc64el signed-by=/usr/share/keyrings/mariadb.gpg] http://mirror.mariadb.org/repo/11.4/ubuntu/ $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/mariadb.list** Refresh APT Package Index After MariaDB Repository Import# apt update** MariaDB Installation# apt install mariadb-server mariadb-client -y# mariadb --versionsystemctl status mariadbsystemctl start mariadbsystemctl enable mariadbsystemctl disable mariadbsystemctl restart mariadb# mysql_secure_installationEnter current password for root (enter for none): EnterSwitch to unix_socket authentication [Y/n] : nChange the root password? [Y/n]: n Remove anonymous users? [Y/n] yDisallow root login remotely? [Y/n] yRemove test database and access to it? [Y/n] yReload privilege tables now? [Y/n] y** connect to MariaDB# mysql# mariadb ------------------------------OR------------------------------------You already have your root account protected, so you can safely answer 'n'.Switch to unix_socket authentication [Y/n] Y <---- Type Y then press the ENTER KEY.You already have your root account protected, so you can safely answer 'n'.Change the root password? [Y/n] Y <---- Type Y then press the ENTER KEY.New password: Remove anonymous users? [Y/n] Y <---- Type Y then press the ENTER KEY.Disallow root login remotely? [Y/n] Y <---- Type Y then press the ENTER KEY.Remove test database and access to it? [Y/n] Y <---- Type Y then press the ENTER KEY. Reload privilege tables now? [Y/n] Y <---- Type Y then press the ENTER KEY.All done! If you've completed all of the above steps, your MariaDBinstallation should now be secure.Thanks for using MariaDB!----------------------------------------------------------------# mariadb-upgradeAccess MariaDB on Ubuntu 24.04 LTS
# mariadb# mariadb -u root -p # [Unix_Socket] authentication is enabled by defaultMariaDB [(none)]> show grants for root@localhost; +-----------------------------------------------------------------------------------------------------------------------------------------+| Grants for root@localhost |+-----------------------------------------------------------------------------------------------------------------------------------------+| GRANT ALL PRIVILEGES ON *.* TO `root`@`localhost` IDENTIFIED VIA mysql_native_password USING 'invalid' OR unix_socket WITH GRANT OPTION || GRANT PROXY ON ''@'%' TO 'root'@'localhost' WITH GRANT OPTION |+-----------------------------------------------------------------------------------------------------------------------------------------+2 rows in set (0.000 sec)# show user listMariaDB [(none)]> select user,host,password from mysql.user; +-------------+-----------+----------+| User | Host | Password |+-------------+-----------+----------+| mariadb.sys | localhost | || root | localhost | invalid || mysql | localhost | invalid |+-------------+-----------+----------+3 rows in set (0.001 sec)# show database listMariaDB [(none)]> show databases; +--------------------+| Database |+--------------------+| information_schema || mysql || performance_schema || sys |+--------------------+4 rows in set (0.000 sec)# create test databaseMariaDB [(none)]> create database test_database; Query OK, 1 row affected (0.000 sec)# create test table on test databaseMariaDB [(none)]> create table test_database.test_table (id int, name varchar(50), address varchar(50), primary key (id)); Query OK, 0 rows affected (0.108 sec)# insert data to test tableMariaDB [(none)]> insert into test_database.test_table(id, name, address) values("001", "Ubuntu", "Hiroshima"); Query OK, 1 row affected (0.036 sec)# show test tableMariaDB [(none)]> select * from test_database.test_table; +----+--------+-----------+| id | name | address |+----+--------+-----------+| 1 | Ubuntu | Hiroshima |+----+--------+-----------+1 row in set (0.000 sec)# delete test databaseMariaDB [(none)]> drop database test_database; Query OK, 1 row affected (0.111 sec)MariaDB [(none)]> exit[3]
If you'd like to delete all data of MariaDB and initialize it, run like follows.
root@www:~# systemctl stop mariadbroot@www:~# rm -rf /var/lib/mysql/*root@www:~# mysql_install_db --datadir=/var/lib/mysql --user=mysqlroot@www:~# systemctl start mariadb ---------------REMOVE-----------------apt autoremove mariadb-server mariadb-client --purge -y rm /etc/apt/sources.list.d/mariadb.list /usr/share/keyrings/mariadb.gpg uninstall MySQL Serversystemctl stop mysqlapt remove --purge *mysql*apt remove --purge *mariadb*rm -rf /etc/mysql /var/lib/mysqlapt autoremoveapt autocleanapt-get dist-upgrade
-------------------------apt-get remove --purge mysql*apt-get purge mysql*apt-get autoremoveapt-get autocleanTo update the system to be up to-date
apt-get dist-upgrade
# apt remove --purge mysql-server
# apt purge mysql-server mysql-client mysql-common mysql-server-core-* mysql-client-core-*Remove Configuration Files and Databases
# rm -rf /etc/mysql /var/lib/mysql
LLInstall and Configure MySQL Server
# sudo apt-get install mysql-server mysql-client -y
sudo apt update && sudo apt install mysql-server
systemctl start mysql
systemctl enable mysql
# mysql_secure_installation
Enter current password for root (enter for none): Set root password? [Y/n]: y Remove anonymous users? [Y/n]: Y Disallow root login remotely? [Y/n]: Y Remove test database and access to it? [Y/n]: Y Reload privilege tables now? [Y/n]: Y
mysql -u root -p
Install MariaDB 10.3 on Ubuntu 18.04
sudo apt-get install software-properties-common
sudo apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8
sudo add-apt-repository 'deb [arch=amd64] http://mirror.zol.co.zw/mariadb/repo/10.3/ubuntu bionic main'
sudo apt update
sudo apt -y install mariadb-server mariadb-client
$ sudo systemctl status mysql
# mysql -u root -p
MariaDB [(none)]> select version();
SELECT User,Host FROM mysql.user;
MariaDB [(none)]> exit
sudo systemctl stop mariadb.service
sudo systemctl start mariadb.service
sudo systemctl restart mariadb.service
sudo systemctl status mariadb.service
# mysql -V
-----------------------------
sudo mysql -u root -p
Create a database called “nextclouddb”
create database nextclouddb;
Grant “nextclouduser” to access the “nextclouddb” database on localhost with a password “password“.
grant all on nextclouddb.* to 'nextclouduser'@'localhost' identified by 'password';
Exit from the MariaDB prompt.
quit
--------------------------------------
Change User Passwd
SET PASSWORD FOR 'phpmyadmin'@'localhost' = PASSWORD('xxxxx');
FLUSH PRIVILEGES;
exit
mariadb> DROP USER 'phpmyadmin'@'localhost';
mariadb> DROP USER phpmyadmin;
sudo systemctl daemon-reload
sudo systemctl restart mysql
sudo systemctl status mariadb
------