Facebook X (Twitter) Instagram
    TecAdmin
    • Home
    • FeedBack
    • Submit Article
    • About Us
    Facebook X (Twitter) Instagram
    TecAdmin
    You are at:Home»Databases»How To Remove MySQL Completely from Your Linux System

    How To Remove MySQL Completely from Your Linux System

    By RahulJanuary 29, 20233 Mins Read

    MySQL is a popular open-source relational database management system. However, sometimes you may need to remove MySQL from your Linux system due to various reasons such as upgrading to a newer version, replacing it with another database system, or simply uninstalling it. In this article, we’ll show you how to remove MySQL completely from your Linux system in a safe and effective manner.

    Before we begin, it is recommended to back up your data and configuration files before uninstalling MySQL. You can use the mysqldump utility to back up your data or copy the entire MySQL data directory to a safe location.

    Here’s the step-by-step guide to removing MySQL from your Linux system:

    Step 1: Stop MySQL Service

    First of all, you need to stop MySQL service on your system.

    sudo systemctl stop mysql 
    

    This stops the MySQL service, allowing you to safely remove the database.

    Step 2: Uninstall MySQL packages

    First, uninstall all the MySQL packages installed on your server. Use one of the following commands as per your Linux distribution. The package names may vary based on the Operating system and installation types.

    • On Debain-based systems
    • sudo apt remove mysql-server mysql-client 
      sudo apt autoremove 
      sudo apt autoclean 
      

    • On RHEL-based systems
    • sudo dnf remove mysql-server mysql-client 
      

    This removes the MySQL packages and their dependencies from your system. The autoremove and autoclean commands remove unnecessary packages and clean up the package cache.

    Step 3: Remove MySQL configuration and data files

    Now we need to remove the MySQL data directory from the system which by default exists at /var/lib/mysql. If you didn’t find this, It may be changed to some other place, which you can find in my.cnf file with variable datadir. Delete the /var/lib/mysql directory from the system but we prefer to rename it to keep a backup of existing files.

    sudo rm -rf /etc/mysql 
    sudo rm -rf /var/lib/mysql 
    

    This removes the MySQL configuration files and data directory. Be careful while removing these files, as they contain important data. Make sure to back up your data before removing these files.

    Step 4: Verify the Removal

    This following command lists all the packages installed on your system, and grep for the word ‘mysql’. If there are no MySQL packages installed, you have successfully removed MySQL from your system.

    dpkg -l | grep -i mysql 
    

    That’s it! You have now successfully removed MySQL from your Linux system. You can now install a different database system or simply enjoy a cleaner system without MySQL.

    Conclusion

    In conclusion, removing MySQL from your Linux system is a straightforward process, but it’s important to back up your data and follow the steps carefully to avoid any data loss. I hope this ultimate guide has been helpful in removing MySQL from your Linux system.

    datadir linux MySQL mysql-server remove-mysql uninstall
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp

    Related Posts

    Working with Python FastAPI and MySQL

    Essential Linux Server Maintenance Checklist

    Resolving MySQL ERROR 1041 (HY000): Out of Memory

    View 12 Comments

    12 Comments

    1. Sumit on August 13, 2017 8:12 am

      Hi Omkar I followed the same step but now I am getting below error can you please suggest ?

      [root@devdesk]# yum install mysql mysql-server
      Loaded plugins: downloadonly, product-id, refresh-packagekit, subscription-manager
      Updating Red Hat repositories.
      http://repo.mysql.com/yum/mysql-connectors-community/el/6/x86_64/repodata/repomd.xml: [Errno 14] PYCURL ERROR 22 – “The requested URL returned error: 403”
      Trying other mirror.
      Error: Cannot retrieve repository metadata (repomd.xml) for repository: mysql-connectors-community. Please verify its path and try again

      Reply
    2. Jim Mason on April 13, 2016 10:07 pm

      There is NOT a simple 1 line command to force yum to overwrite or remove a complete install package set like mariadb. it’s an ugly process so far to get an install of a different version of mysql. It has multiple entries in the local yum repo to erase.

      run
      yum list all > yum_list_all.txt

      search that for both maria and mysql.
      remove ALL those entries found from the yum repo .. e.g.

      yum erase mariadb-libs.x86_64

      also find all references on disk to folders with maria or mysql

      rm -fr

      now, in theory, you have a clean starting point to begin adding mysql packages to yum specifically that you will download and install

      Reply
    3. Tarikul Islam on February 10, 2016 6:40 pm

      I am looking for this, thanks for sharing with us.

      Reply
    4. abi on December 21, 2015 10:49 am

      When i give this command : yum remove mysql mysql-server
      it shows : You need to be root to perform this command.
      I am not able to connect with root

      Reply
      • Omair on December 29, 2015 11:59 am

        Log in as root then, for this type the command below:
        su –
        (Provide your password when prompted for)
        In case you do not have any root credentials then try using sudo command. i.e
        sudo yum remove mysql mysql-server
        If this does not help then you really need to contact your system administrator.

        Reply
    5. Henrique on October 24, 2015 7:20 pm

      Perfect! Exactly what I needed! But it is only for Fedora/Redhat.

      Reply
    6. agen bola on October 9, 2015 11:14 am

      nice share, and What you want to know how to resolve the issue??

      Reply
    7. 338A on August 3, 2015 3:25 am

      i have a problem with the command, can u give any solution?

      Reply
    8. Veerabadra on June 3, 2015 8:32 am

      I have followed the above steps and the system throws the below error.

      ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’ (2)
      Any one can help me?

      Reply
      • Keyndin on December 4, 2015 3:38 pm

        Although I hope you have fixed your issue already I thought I might post my answer regardless since I had the same issue after completing all the above steps.

        Simply run “service mysqld start” before connecting to your database and the issue should be fixed.

        Reply
    9. tudor on May 27, 2015 1:48 pm

      Exactly what I needed! Thanks!

      Reply
    10. Omkar on February 7, 2015 9:35 am

      Extremely simple explanation that lead to successful uninstallation.

      Thank you so much Rahul.

      Reply

    Leave A Reply Cancel Reply

    Advertisement
    Recent Posts
    • Using .env Files in Django
    • Using .env File in FastAPI
    • Setting Up Email Notifications for Django Error Reporting
    • How to Enable Apache Rewrite (mod_rewrite) Module
    • What are Microservices?
    Facebook X (Twitter) Instagram Pinterest
    © 2023 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.