title: Can't install MySQL on Ubuntu 16.04
body: <p>I installed <code>mariadb-server</code> before installing <code>mysql-server</code> (which I wasn't supposed to do), so I purged <code>mariadb*</code> and removed it from the repos. However, I can't install <code>mysql-server</code>.</p>
  
  <p>After <code>sudo apt-get install mysql-server</code>, I get:</p>
  
  <pre><code>Setting up mysql-server-5.7 (5.7.19-0ubuntu0.16.04.1) ...
  invoke-rc.d: could not determine current runlevel
   * Stopping MySQL database server mysqld                                                                                                                                     [ OK ] update-alternatives: using /etc/mysql/mysql.cnf to provide /etc/mysql/my.cnf (my.cnf) in auto mode
  Renaming removed key_buffer and myisam-recover options (if present)
  invoke-rc.d: could not determine current runlevel
  invoke-rc.d: could not determine current runlevel
   * Stopping MySQL database server mysqld                                                                                                                                     [ OK ] invoke-rc.d: could not determine current runlevel
  mysql_upgrade: Got error: 2002: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) while connecting to the MySQL server
  Upgrade process encountered error and will not continue.
  mysql_upgrade failed with exit status 11
  dpkg: error processing package mysql-server-5.7 (--configure):
   subprocess installed post-installation script returned error exit status 1
  Setting up libhtml-tagset-perl (3.20-2) ...
  Setting up liburi-perl (1.71-1) ...
  Setting up libhtml-parser-perl (3.72-1) ...
  Setting up libcgi-pm-perl (4.26-1) ...
  Setting up libfcgi-perl (0.77-1build1) ...
  Setting up libcgi-fast-perl (1:2.10-1) ...
  Setting up libencode-locale-perl (1.05-1) ...
  Setting up libhtml-template-perl (2.95-2) ...
  Setting up libtimedate-perl (2.3000-2) ...
  Setting up libhttp-date-perl (6.02-1) ...
  Setting up libio-html-perl (1.001-1) ...
  Setting up liblwp-mediatypes-perl (6.02-1) ...
  Setting up libhttp-message-perl (6.11-1) ...
  dpkg: dependency problems prevent configuration of mysql-server:
   mysql-server depends on mysql-server-5.7; however:
    Package mysql-server-5.7 is not configured yet.
  
  dpkg: error processing package mysql-server (--configure):
   dependency problems - leaving unconfigured
  Processing triggers for libc-bin (2.23-0ubuntu9) ...
  No apport report written because the error message indicates its a followup error from a previous failure.
                                                                                                            Processing triggers for systemd (229-4ubuntu19) ...
  Processing triggers for ureadahead (0.100.0-19) ...
  Errors were encountered while processing:
   mysql-server-5.7
  E: Sub-process /usr/bin/dpkg returned an error code (1)
  </code></pre>
  
  <p>After running <code>sudo apt-get install -f</code>, I get:</p>
  
  <pre><code>Setting up mysql-server-5.7 (5.7.19-0ubuntu0.16.04.1) ...
  invoke-rc.d: could not determine current runlevel
   * Stopping MySQL database server mysqld                                                                                                                                     [ OK ] Renaming removed key_buffer and myisam-recover options (if present)
  invoke-rc.d: could not determine current runlevel
  invoke-rc.d: could not determine current runlevel
   * Stopping MySQL database server mysqld                                                                                                                                     [ OK ] invoke-rc.d: could not determine current runlevel
  mysql_upgrade: Got error: 2002: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) while connecting to the MySQL server
  Upgrade process encountered error and will not continue.
  mysql_upgrade failed with exit status 11
  dpkg: error processing package mysql-server-5.7 (--configure):
   subprocess installed post-installation script returned error exit status 1
  dpkg: dependency problems prevent configuration of mysql-server:
   mysql-server depends on mysql-server-5.7; however:
    Package mysql-server-5.7 is not configured yet.
  
  dpkg: error processing package mysql-server (--configure):
   dependency problems - leaving unconfigured
  No apport report written because the error message indicates its a followup error from a previous failure.
                                                                                                            Errors were encountered while processing:
   mysql-server-5.7
   mysql-server
  E: Sub-process /usr/bin/dpkg returned an error code (1)
  </code></pre>
  
  <p>How do I get around these errors and install <code>mysql-server</code>?</p>