DEV Community

Cover image for Remove MariaDB from your Ubuntu system using the terminal
MuthuKumar
MuthuKumar

Posted on • Updated on

Remove MariaDB from your Ubuntu system using the terminal

To remove MariaDB from your Ubuntu system using the terminal, follow these steps:

Note: Removing software can have unintended consequences. Be sure you have a backup of any important data before proceeding.

  1. Stop MariaDB Service: Before removing MariaDB, stop the MariaDB service to prevent any issues during the uninstallation process. Open a terminal and run:


   sudo systemctl stop mariadb


Enter fullscreen mode Exit fullscreen mode
  1. Uninstall MariaDB: You can use the apt package manager to uninstall MariaDB:


   sudo apt-get remove --purge mariadb-server mariadb-client mariadb-common


Enter fullscreen mode Exit fullscreen mode

This command will remove the MariaDB server, client, and common packages. The --purge option ensures that configuration files are also removed.

  1. Remove Configuration Files: Sometimes, after uninstalling a package, configuration files are left behind. To remove these configuration files, run:


   sudo apt-get purge mariadb-server-*


Enter fullscreen mode Exit fullscreen mode
  1. Remove Data Directory (Optional): If you want to remove all data associated with MariaDB (including databases), you can remove the data directory. Be very cautious with this step, as it will permanently delete all your MariaDB data.


   sudo rm -r /var/lib/mysql


Enter fullscreen mode Exit fullscreen mode
  1. Clean Up: Finally, run the following command to clean up any residual packages and dependencies that are no longer required:


   sudo apt-get autoremove


Enter fullscreen mode Exit fullscreen mode
  1. Check for Remaining Files (Optional): You can also check if there are any remaining files related to MariaDB:


   dpkg -l | grep mariadb


Enter fullscreen mode Exit fullscreen mode

If there are any remaining packages, you can manually remove them using the sudo apt-get remove command.

Remember, these steps will completely remove MariaDB from your system, including all databases and configuration. Make sure you have a backup of any important data before proceeding.

Try it Yourself :

Check mariadb Status:



muthukumar@DevOpsEngineer:~$ sudo systemctl status mariadb
[sudo] password for muthukumar: 
● mariadb.service - MariaDB 10.6.12 database server
     Loaded: loaded (/lib/systemd/system/mariadb.service; enabled; vendor prese>
     Active: active (running) since Wed 2023-08-16 11:22:49 IST; 2h 6min ago
       Docs: man:mariadbd(8)
             https://mariadb.com/kb/en/library/systemd/
   Main PID: 984 (mariadbd)
     Status: "Taking your SQL requests now..."
      Tasks: 8 (limit: 9110)
     Memory: 94.5M
        CPU: 2.070s
     CGroup: /system.slice/mariadb.service
             └─984 /usr/sbin/mariadbd

Aug 16 11:22:49 DevOpsEngineer mariadbd[984]: Version: '10.6.12-MariaDB-0ubuntu>
Aug 16 11:22:49 DevOpsEngineer systemd[1]: Started MariaDB 10.6.12 database ser>
Aug 16 11:22:49 DevOpsEngineer /etc/mysql/debian-start[1195]: Upgrading MySQL t>
Aug 16 11:22:49 DevOpsEngineer /etc/mysql/debian-start[1202]: Looking for 'mari>
Aug 16 11:22:49 DevOpsEngineer /etc/mysql/debian-start[1202]: Looking for 'mari>
Aug 16 11:22:49 DevOpsEngineer /etc/mysql/debian-start[1202]: This installation>
Aug 16 11:22:49 DevOpsEngineer /etc/mysql/debian-start[1202]: There is no need >
Aug 16 11:22:49 DevOpsEngineer /etc/mysql/debian-start[1202]: You can use --for>
Aug 16 11:22:49 DevOpsEngineer /etc/mysql/debian-start[1246]: Checking for inse>
Aug 16 11:22:49 DevOpsEngineer /etc/mysql/debian-start[1250]: Triggering myisam>
lines 1-23



Enter fullscreen mode Exit fullscreen mode

Stop MariaDB Service:



muthukumar@DevOpsEngineer:~$ sudo systemctl stop mariadb
muthukumar@DevOpsEngineer:~$ sudo systemctl status mariadb
○ mariadb.service - MariaDB 10.6.12 database server
     Loaded: loaded (/lib/systemd/system/mariadb.service; enabled; vendor prese>
     Active: inactive (dead) since Wed 2023-08-16 13:29:55 IST; 4s ago
       Docs: man:mariadbd(8)
             https://mariadb.com/kb/en/library/systemd/
    Process: 984 ExecStart=/usr/sbin/mariadbd $MYSQLD_OPTS $_WSREP_NEW_CLUSTER >
   Main PID: 984 (code=exited, status=0/SUCCESS)
     Status: "MariaDB server is down"
        CPU: 2.087s

Aug 16 13:29:54 DevOpsEngineer mariadbd[984]: 2023-08-16 13:29:54 0 [Note] Inno>
Aug 16 13:29:54 DevOpsEngineer mariadbd[984]: 2023-08-16 13:29:54 0 [Note] Inno>
Aug 16 13:29:54 DevOpsEngineer mariadbd[984]: 2023-08-16 13:29:54 0 [Note] Inno>
Aug 16 13:29:54 DevOpsEngineer mariadbd[984]: 2023-08-16 13:29:54 0 [Note] Inno>
Aug 16 13:29:55 DevOpsEngineer mariadbd[984]: 2023-08-16 13:29:55 0 [Note] Inno>
Aug 16 13:29:55 DevOpsEngineer mariadbd[984]: 2023-08-16 13:29:55 0 [Note] Inno>
Aug 16 13:29:55 DevOpsEngineer mariadbd[984]: 2023-08-16 13:29:55 0 [Note] /usr>
Aug 16 13:29:55 DevOpsEngineer systemd[1]: mariadb.service: Deactivated success>
Aug 16 13:29:55 DevOpsEngineer systemd[1]: Stopped MariaDB 10.6.12 database ser>
Aug 16 13:29:55 DevOpsEngineer systemd[1]: mariadb.service: Consumed 2.087s CPU>
lines 1-20/20 (END)...skipping...
○ mariadb.service - MariaDB 10.6.12 database server
     Loaded: loaded (/lib/systemd/system/mariadb.service; enabled; vendor preset: enabled)
     Active: inactive (dead) since Wed 2023-08-16 13:29:55 IST; 4s ago
       Docs: man:mariadbd(8)
             https://mariadb.com/kb/en/library/systemd/
    Process: 984 ExecStart=/usr/sbin/mariadbd $MYSQLD_OPTS $_WSREP_NEW_CLUSTER $_WSREP_START_POSITION (code=exited, status=0/SUCCESS)
   Main PID: 984 (code=exited, status=0/SUCCESS)
     Status: "MariaDB server is down"
        CPU: 2.087s

Aug 16 13:29:54 DevOpsEngineer mariadbd[984]: 2023-08-16 13:29:54 0 [Note] InnoDB: FTS optimize thread exiting.
Aug 16 13:29:54 DevOpsEngineer mariadbd[984]: 2023-08-16 13:29:54 0 [Note] InnoDB: Starting shutdown...
Aug 16 13:29:54 DevOpsEngineer mariadbd[984]: 2023-08-16 13:29:54 0 [Note] InnoDB: Dumping buffer pool(s) to /var/lib/mysql/ib_buffer_pool
Aug 16 13:29:54 DevOpsEngineer mariadbd[984]: 2023-08-16 13:29:54 0 [Note] InnoDB: Buffer pool(s) dump completed at 230816 13:29:54
Aug 16 13:29:55 DevOpsEngineer mariadbd[984]: 2023-08-16 13:29:55 0 [Note] InnoDB: Removed temporary tablespace data file: "./ibtmp1"
Aug 16 13:29:55 DevOpsEngineer mariadbd[984]: 2023-08-16 13:29:55 0 [Note] InnoDB: Shutdown completed; log sequence number 2128302; transaction id 738
Aug 16 13:29:55 DevOpsEngineer mariadbd[984]: 2023-08-16 13:29:55 0 [Note] /usr/sbin/mariadbd: Shutdown complete
Aug 16 13:29:55 DevOpsEngineer systemd[1]: mariadb.service: Deactivated successfully.
Aug 16 13:29:55 DevOpsEngineer systemd[1]: Stopped MariaDB 10.6.12 database server.
Aug 16 13:29:55 DevOpsEngineer systemd[1]: mariadb.service: Consumed 2.087s CPU time.
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
lines 1-20/20 (END)



Enter fullscreen mode Exit fullscreen mode

Uninstall MariaDB:

Step 1:



muthukumar@DevOpsEngineer:~$ sudo apt-get remove --purge mariadb-server mariadb-client mariadb-common
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages were automatically installed and are no longer required:
  galera-4 libcgi-fast-perl libcgi-pm-perl libconfig-inifiles-perl libdaxctl1 libdbd-mysql-perl libdbi-perl libfcgi-bin libfcgi-perl libfcgi0ldbl
  libhtml-template-perl libndctl6 libpmem1 libterm-readkey-perl socat
Use 'sudo apt autoremove' to remove them.
The following packages will be REMOVED:
  libmariadb3* mariadb-client* mariadb-client-10.6* mariadb-client-core-10.6* mariadb-common* mariadb-server* mariadb-server-10.6*
  mariadb-server-core-10.6*
0 upgraded, 0 newly installed, 8 to remove and 52 not upgraded.
After this operation, 149 MB disk space will be freed.
Do you want to continue? [Y/n] Y



Enter fullscreen mode Exit fullscreen mode

click yes

Image description



muthukumar@DevOpsEngineer:~$ sudo apt-get remove --purge mariadb-server mariadb-client mariadb-common
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages were automatically installed and are no longer required:
  galera-4 libcgi-fast-perl libcgi-pm-perl libconfig-inifiles-perl libdaxctl1 libdbd-mysql-perl libdbi-perl libfcgi-bin libfcgi-perl libfcgi0ldbl
  libhtml-template-perl libndctl6 libpmem1 libterm-readkey-perl socat
Use 'sudo apt autoremove' to remove them.
The following packages will be REMOVED:
  libmariadb3* mariadb-client* mariadb-client-10.6* mariadb-client-core-10.6* mariadb-common* mariadb-server* mariadb-server-10.6*
  mariadb-server-core-10.6*
0 upgraded, 0 newly installed, 8 to remove and 52 not upgraded.
After this operation, 149 MB disk space will be freed.
Do you want to continue? [Y/n] Y
(Reading database ... 242230 files and directories currently installed.)
Removing mariadb-client (1:10.6.12-0ubuntu0.22.04.1) ...
Removing mariadb-server (1:10.6.12-0ubuntu0.22.04.1) ...
Removing mariadb-server-10.6 (1:10.6.12-0ubuntu0.22.04.1) ...
Removing mariadb-client-10.6 (1:10.6.12-0ubuntu0.22.04.1) ...
Removing mariadb-client-core-10.6 (1:10.6.12-0ubuntu0.22.04.1) ...
Removing libmariadb3:amd64 (1:10.6.12-0ubuntu0.22.04.1) ...
Removing mariadb-server-core-10.6 (1:10.6.12-0ubuntu0.22.04.1) ...
Removing mariadb-common (1:10.6.12-0ubuntu0.22.04.1) ...
update-alternatives: using /etc/mysql/my.cnf.fallback to provide /etc/mysql/my.cnf (my.cnf) in auto mode
Processing triggers for man-db (2.10.2-1) ...
Processing triggers for libc-bin (2.35-0ubuntu3.1) ...
(Reading database ... 241888 files and directories currently installed.)
Purging configuration files for mariadb-common (1:10.6.12-0ubuntu0.22.04.1) ...
Purging configuration files for mariadb-server-10.6 (1:10.6.12-0ubuntu0.22.04.1) ...
Purging configuration files for mariadb-client-10.6 (1:10.6.12-0ubuntu0.22.04.1) ...
muthukumar@DevOpsEngineer:~$ 



Enter fullscreen mode Exit fullscreen mode

Remove Configuration Files:



muthukumar@DevOpsEngineer:~$ sudo apt-get purge mariadb-server-*
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Note, selecting 'mariadb-server-core-5.5' for glob 'mariadb-server-*'
Note, selecting 'mariadb-server-5.1' for glob 'mariadb-server-*'
Note, selecting 'mariadb-server-5.2' for glob 'mariadb-server-*'
Note, selecting 'mariadb-server-5.3' for glob 'mariadb-server-*'
Note, selecting 'mariadb-server-5.5' for glob 'mariadb-server-*'
Note, selecting 'mariadb-server-core-10.0' for glob 'mariadb-server-*'
Note, selecting 'mariadb-server-core-10.1' for glob 'mariadb-server-*'
Note, selecting 'mariadb-server-core-10.2' for glob 'mariadb-server-*'
Note, selecting 'mariadb-server-core-10.3' for glob 'mariadb-server-*'
Note, selecting 'mariadb-server-core-10.4' for glob 'mariadb-server-*'
Note, selecting 'mariadb-server-core-10.5' for glob 'mariadb-server-*'
Note, selecting 'mariadb-server-core-10.6' for glob 'mariadb-server-*'
Note, selecting 'mariadb-server-10.0' for glob 'mariadb-server-*'
Note, selecting 'mariadb-server-10.1' for glob 'mariadb-server-*'
Note, selecting 'mariadb-server-10.2' for glob 'mariadb-server-*'
Note, selecting 'mariadb-server-10.3' for glob 'mariadb-server-*'
Note, selecting 'mariadb-server-10.4' for glob 'mariadb-server-*'
Note, selecting 'mariadb-server-10.5' for glob 'mariadb-server-*'
Note, selecting 'mariadb-server-10.6' for glob 'mariadb-server-*'
Package 'mariadb-server-5.5' is not installed, so not removed
Package 'mariadb-server-10.1' is not installed, so not removed
Package 'mariadb-server-10.3' is not installed, so not removed
Package 'mariadb-server-core-10.1' is not installed, so not removed
Package 'mariadb-server-core-10.3' is not installed, so not removed
Package 'mariadb-server-10.0' is not installed, so not removed
Package 'mariadb-server-5.1' is not installed, so not removed
Package 'mariadb-server-5.2' is not installed, so not removed
Package 'mariadb-server-5.3' is not installed, so not removed
Package 'mariadb-server-10.2' is not installed, so not removed
Package 'mariadb-server-10.4' is not installed, so not removed
Package 'mariadb-server-10.5' is not installed, so not removed
Package 'mariadb-server-core-10.0' is not installed, so not removed
Package 'mariadb-server-core-10.2' is not installed, so not removed
Package 'mariadb-server-core-10.4' is not installed, so not removed
Package 'mariadb-server-core-10.5' is not installed, so not removed
Package 'mariadb-server-core-5.5' is not installed, so not removed
Package 'mariadb-server-10.6' is not installed, so not removed
Package 'mariadb-server-core-10.6' is not installed, so not removed
The following packages were automatically installed and are no longer required:
  galera-4 libcgi-fast-perl libcgi-pm-perl libconfig-inifiles-perl libdaxctl1 libdbd-mysql-perl libdbi-perl libfcgi-bin libfcgi-perl libfcgi0ldbl
  libhtml-template-perl libndctl6 libpmem1 libterm-readkey-perl socat
Use 'sudo apt autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 52 not upgraded.
muthukumar@DevOpsEngineer:~$ 



Enter fullscreen mode Exit fullscreen mode

Remove Data Directory (Optional):

Step 1:



muthukumar@DevOpsEngineer:~$ sudo rm -r /var/lib/mysql
rm: cannot remove '/var/lib/mysql': No such file or directory


Enter fullscreen mode Exit fullscreen mode

step 2:



muthukumar@DevOpsEngineer:/var/lib$ ls
AccountsService  boltd                fwupd        locales         os-prober              saned         tpm                      upower
acpi-support     BrlAPI               gdm3         logrotate       PackageKit             sgml-base     ubiquity                 usb_modeswitch
alsa             colord               geoclue      man-db          pam                    shells.state  ubuntu-advantage         usbutils
apache2          command-not-found    ghostscript  misc            php                    shim-signed   ubuntu-drivers-common    vim
app-info         dbus                 git          mysql-8.0       plocate                snapd         ubuntu-release-upgrader  whoopsie
apport           dhcp                 grub         mysql-files     plymouth               snmp          ucf                      xfonts
apt              dictionaries-common  hp           mysql-keyring   polkit-1               sudo          udisks2                  xkb
aspell           dpkg                 ispell       NetworkManager  power-profiles-daemon  swcatalog     unattended-upgrades      xml-core
avahi-autoipd    emacsen-common       jenkins      nginx           private                systemd       update-manager
bluetooth        fprint               libreoffice  openvpn         python                 tlp           update-notifier



Enter fullscreen mode Exit fullscreen mode

step 3:



muthukumar@DevOpsEngineer:/var/lib$ cd m
man-db/        misc/          mysql-8.0/     mysql-files/   mysql-keyring/ 


Enter fullscreen mode Exit fullscreen mode

step 4:



muthukumar@DevOpsEngineer:~$ sudo rm -r /var/lib/mysql-8.0/
muthukumar@DevOpsEngineer:~$ sudo rm -r /var/lib/mysql-files/
muthukumar@DevOpsEngineer:~$ sudo rm -r /var/lib/mysql-keyring/



Enter fullscreen mode Exit fullscreen mode

Clean Up:



muthukumar@DevOpsEngineer:~$ sudo apt-get autoremove
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages will be REMOVED:
  galera-4 libcgi-fast-perl libcgi-pm-perl libconfig-inifiles-perl libdaxctl1 libdbd-mysql-perl libdbi-perl libfcgi-bin libfcgi-perl libfcgi0ldbl
  libhtml-template-perl libndctl6 libpmem1 libterm-readkey-perl socat
0 upgraded, 0 newly installed, 15 to remove and 52 not upgraded.
After this operation, 7,362 kB disk space will be freed.
Do you want to continue? [Y/n] Y
(Reading database ... 241873 files and directories currently installed.)
Removing galera-4 (26.4.9-1build1) ...
Removing libcgi-fast-perl (1:2.15-1) ...
Removing libhtml-template-perl (2.97-1.1) ...
Removing libcgi-pm-perl (4.54-1) ...
Removing libconfig-inifiles-perl (3.000003-1) ...
Removing libpmem1:amd64 (1.11.1-3build1) ...
Removing libndctl6:amd64 (72.1-1) ...
Removing libdaxctl1:amd64 (72.1-1) ...
Removing libdbd-mysql-perl:amd64 (4.050-5) ...
Removing libdbi-perl:amd64 (1.643-3build3) ...
Removing libfcgi-bin (2.4.2-2build2) ...
Removing libfcgi-perl:amd64 (0.82+ds-1build1) ...
Removing libfcgi0ldbl:amd64 (2.4.2-2build2) ...
Removing libterm-readkey-perl (2.38-1build4) ...
Removing socat (1.7.4.1-3ubuntu4) ...
Processing triggers for man-db (2.10.2-1) ...
Processing triggers for libc-bin (2.35-0ubuntu3.1) ...
muthukumar@DevOpsEngineer:~$ 



Enter fullscreen mode Exit fullscreen mode

Check for Remaining Files (Optional):



muthukumar@DevOpsEngineer:~$ dpkg -l | grep mariadb


Enter fullscreen mode Exit fullscreen mode

END

Top comments (0)