SE-Foundation Help

[How to : ] Fresh Reset and Install mysql 5.7

⚠️ Before going through the guide try this command if it gonna install MySQL 5.7 correctly, when you see the white windows you can jump to step 9, and see what to choose :

#!/usr/bin/env bash # sudo wget -O mysql57 https://raw.githubusercontent.com/nuuxcode/alx-system_engineering-devops/master/scripts/mysql57 && sudo chmod +x mysql57 && sudo ./mysql57 echo "" echo "if wanna read the guide:" echo "https://docs.google.com/document/d/1btVRofXP75Cj90_xq2x8AmzuMPOKq6D_Dt_SCDD6GrU/" echo "" echo "" echo "-------------------------------" echo "# Remove Existing MySQL Versions" echo "-------------------------------" echo "" sudo apt-get remove --purge mysql-server mysql-client mysql-common -y && sudo apt-get autoremove -y echo "" echo "-------------------------------" echo "# Remove MySQL Apt Configuration" echo "-------------------------------" echo "" sudo rm -rf /etc/apt/sources.list.d/mysql.list* sudo rm -rf /var/lib/mysql-apt-config sudo dpkg --purge mysql-apt-config echo "" echo "-------------------------------" echo "# Remove MySQL Configuration Files" echo "-------------------------------" echo "" sudo rm -rf /etc/mysql /var/lib/mysql echo "Done!" echo "" echo "-------------------------------" echo "# Update Packages" echo "-------------------------------" echo "" sudo apt update echo "" echo "-------------------------------" echo "# Clean APT Cache" echo "-------------------------------" echo "" sudo apt clean echo "Done!" echo "" echo "-------------------------------" echo "# Configure Any Pending Packages" echo "-------------------------------" echo "" sudo dpkg --configure -a echo "Done!" echo "" echo "-------------------------------" echo "# Download and Install MySQL APT configuration package" echo "-------------------------------" echo "" sudo wget -O mysql-apt-config_0.8.12-1_all.deb https://dev.mysql.com/get/mysql-apt-config_0.8.12-1_all.deb echo "mysql-apt-config mysql-apt-config/select-server select mysql-5.7" | sudo debconf-set-selections echo "mysql-apt-config mysql-apt-config/select-server-5.7 select bionic" | sudo debconf-set-selections sudo dpkg -i mysql-apt-config_0.8.12-1_all.deb echo "" echo "-------------------------------" echo "# Import the GPG key for the MySQL repository" echo "-------------------------------" echo "" sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 467B942D3A79BD29 sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys B7B3B788A8D3785C echo "" echo "-------------------------------" echo "# Update Packages" echo "-------------------------------" echo "" sudo apt update echo "" echo "-------------------------------" echo "# Display information MySQL server package" echo "-------------------------------" echo "" sudo apt-cache policy mysql-server echo "" echo "-------------------------------" echo "# Install MySQL 5.7" echo "-------------------------------" echo "" sudo apt install -f mysql-client=5.7* mysql-community-server=5.7* mysql-server=5.7* -y echo "" echo "-------------------------------" echo "# Check if MySQL 5.7 installed correctly" echo "-------------------------------" echo "" sudo mysql --version echo ""
sudo chmod +x mysql57 sudo ./mysql57

If this command did not install 5.7 correctly you can continue reading the following guide.

You can also use this guide for more visual and sample outputs : For a comprehensive Guide Click Here 📄

STEPS:

  1. Clean Running MySQL Processes:

    • Check for any running MYSQL Processes:

      sudo ps aux | grep mysql
    • If MySQL is running, try stopping it:

      sudo service mysql stop
    • Double-check if MySQL is no longer running:

      sudo ps aux | grep mysql
    • If MySQL processes are still running, terminate them, remember to replace PID with the value of your PID:

      sudo kill -9 <PID>
  2. Remove Existing MySQL Versions:

    • Remove MySQL packages:

      sudo apt-get remove --purge mysql-server mysql-client mysql-common -y && sudo apt-get autoremove -y
    • If no errors occur, proceed to next steps

    • If prompted by a dialog to remove data directories, please select YES and press Enter.

  3. Remove MySQL Apt Configurations:

    • Running the following:

      sudo rm -rf /etc/apt/sources.list.d/mysql.list*
      sudo rm -rf /var/lib/mysql-apt-config
      sudo dpkg --purge mysql-apt-config
  4. Double Check and Remove Configuration File:

    • Check by running:

      dpkg -l | grep mysql
    • The result from above should be none, on your terminal

    • Now, Remove configuration files by:

      sudo rm -rf /etc/mysql /var/lib/mysql
  5. Edit sources.list to Remove MySQL Repositories:

    • Check the sources.list file for MySQL repository entries (example: deb http://repo.mysql.com/apt/ubuntu bionic main), there should be none like the picture below:

    • Update the packages:

    • Check the sources.list file for MySQL repository entries (example: deb http://repo.mysql.com/apt/ubuntu bionic main),

    • Run:

      cat /etc/apt/sources.list | grep mysql
    • There should be none like the picture below:

    • If there are entries, open the sources.list file:

      sudo vi /etc/apt/sources.list
    • If no errors occur, proceed to the next step.

    • Update the package by running:

      sudo apt update
    • Kill any running processes:

      ps aux | grep apt
  6. Clean APT Cache:

    • Run:

      sudo apt clean
  7. Configure any Pending Packages and Install MySQL:

    • Run:

      sudo dpkg --configure -a
    • Install MySQL by running:

      sudo wget -O mysql57 https://raw.githubusercontent.com/nuuxcode/alx-system_engineering-devops/master/scripts/mysql57 && sudo chmod +x mysql57 && sudo ./mysql57
    • A few windows are going to show up. Follow the prompts to select Ubuntu Bionic, change to MySQL 5.7, and set a password if needed.

    • After installation, check MySQL status:

      sudo service mysql status

If issues persist, use the following commands to debug:

journalctl -u mysql.service
cat /var/log/mysql/error.log
journalctl -xe

Check this post to learn more about MySQL: https://shazaali.substack.com/p/database-administration

    Last modified: 05 September 2024