Completely stuck on install / service stop MYSQL

The following steps are generally to solve a "worst-case scenario", where there are processes running that you cannot identify the owner and you just need to put a stop to it. If this is a new Ubuntu Server 20.04 installation that you put on the machine yourself, then something that you installed also put MySQL (or MariaDB) on the machine. Before getting too crazy and killing processes, let's confirm the version of MySQL that is installed on your server:

$ mysql -V

If you see something like this next line, then perhaps you don't need to install MySQL at all:

mysql  Ver 8.0.23-0ubuntu0.20.04.1 for Linux on x86_64 ((Ubuntu))

Figure out where the installation came from, connect with sudo (eg. sudo mysql), and get the database ready for WordPress.

Otherwise ... let's scorch some earth.


Important

The following set of instructions will do a couple of things:

  1. Kill the currently-running MySQL process that does not respond to the standard stop command
  2. Remove the currently installed version of MySQL
  3. Install the Canonical release of MySQL Server

With the disclaimer out of the way, let's go hunting for MySQL:

  1. Use top (or any other process-viewing tool) to identify the PID for MySQL:

    $ sudo top -p `pgrep mysql | tr "\\n" "," | sed 's/,$//'`
    

    Note: You could simply use sudo top, but the command above will limit the output to only MySQL, saving time.

    You should get something that looks similar to this:

    top - 23:31:12 up 10 days, 22:02,  2 users,  load average: 0.01, 0.04, 0.00
    Tasks:   1 total,   0 running,   1 sleeping,   0 stopped,   0 zombie
    %Cpu(s):  0.3 us,  0.3 sy,  0.0 ni, 99.2 id,  0.1 wa,  0.0 hi,  0.1 si,  0.0 st
    MiB Mem :   7725.7 total,    141.2 free,   3083.2 used,   4501.3 buff/cache
    MiB Swap:  31250.0 total,  31026.2 free,    223.8 used.   3577.0 avail Mem 
    
        PID USER      PR  NI    VIRT    RES    SHR S  %CPU  %MEM     TIME+ COMMAND
     112265 mysql     20   0 3979708 693688  13032 S   0.3   8.8  50:35.45 mysqld
    
  2. (This is horrible for so many reasons, but ...) Kill the process. If you do this from within top, press K, then the PID number. If you choose to kill the process from the command line, you can do it like this:

    $ sudo kill -9 112265
    

    Note: Be sure to change 112265 to whatever value you see for MySQL.

  3. Check which MySQL packages are currently installed on your system:

    $ sudo apt list "mysql*" --installed
    

    You will likely see something that looks like this, but with different version numbers:

    Listing... Done
    mysql-client-8.0/focal-security,now 8.0.23-0ubuntu0.20.04.1 amd64 [installed,automatic]
    mysql-client-core-8.0/focal-security,now 8.0.23-0ubuntu0.20.04.1 amd64 [installed,automatic]
    mysql-client/focal-security,focal-security,now 8.0.23-0ubuntu0.20.04.1 all [installed]
    mysql-common/focal,focal,now 5.8+1.0.5ubuntu2 all [installed,automatic]
    mysql-server-8.0/focal-security,now 8.0.23-0ubuntu0.20.04.1 amd64 [installed,automatic]
    mysql-server-core-8.0/focal-security,now 8.0.23-0ubuntu0.20.04.1 amd64 [installed,automatic]
    mysql-server/focal-security,focal-security,now 8.0.23-0ubuntu0.20.04.1 all [installed]
    
  4. Scrub MySQL from the system:

    $ sudo apt purge mysql-server mysql-client \
                     mysql-common "mysql-server-core-*" "mysql-client-core-*"
    

    Note: You will get a long list of packages to be removed. Look at those packages. Make sure you understand what will be eliminated from the system. If you are comfortable with their removal, agree to the prompt and let apt do its thing.

  5. Ensure that apt is clean and up-to-date:

    $ sudo apt autoremove
    $ sudo apt autoclean
    $ sudo apt update
    
  6. Re-install MySQL Server:

    $ sudo apt install mysql-server
    
  7. Run the secure installation procedure and set a good root password:

    $ sudo mysql_secure_installation
    
  8. When done, connect to MySQL and make sure everything is working:

    $ sudo mysql
    

    If you can sign in, then the server is working. You can also take a look at the existing databases (which should be limited to just system databases if this is really the first time MySQL has been installed).

    mysql> SHOW DATABASES;
    +--------------------+
    | Database           |
    +--------------------+
    | information_schema |
    | mysql              |
    | performance_schema |
    | sys                |
    +--------------------+
    4 rows in set (0.00 sec)
    
  9. Create yourself an administrator account, because you cannot have WordPress (or any other tool) connect to MySQL as root:

    CREATE USER 'victoroos'@'localhost' IDENTIFIED WITH mysql_native_password BY 'SuperSecretPassword!123';
    

    Also give that account all privileges so that it is essentially a root account:

    GRANT ALL ON *.* TO 'victoroos'@'localhost' WITH GRANT OPTION;
    
  10. Install WordPress ... or Apache & PHP if you haven't already done so.