Mysql crashed and won't start up

Solution 1:

Ouch.

InnoDB: immediately after the mysqld startup, there may be
InnoDB: corruption in the InnoDB tablespace. Please refer to
InnoDB: http://dev.mysql.com/doc/refman/5.1/en/forcing-recovery.html
InnoDB: about forcing recovery.

Check the suggested webpage: http://dev.mysql.com/doc/refman/5.1/en/forcing-recovery.html.

Basically, try to start the MySQL server in a recovery mode and make a backup of your crashed tables.

Edit your /etc/my.cnf and add:

 innodb_force_recovery = 1

...to see if you can get into your database and get your data / find the corrupted table.

Usually, when this happens it's a re-build (at least of a corrupted table or two).

From http://chepri.com/mysql-innodb-corruption-and-recovery/:

  1. Stop mysqld (service mysql stop).
  2. Backup /var/lib/mysql/ib*
  3. Add the following line into /etc/my.cnf:

    innodb_force_recovery = 1
    

    (they suggest 4, but its best to start with 1 and increment if it won't start)

  4. Restart mysqld (service mysql start).

  5. Dump all tables: mysqldump -A > dump.sql
  6. Drop all databases which need recovery.
  7. Stop mysqld (service mysql stop).
  8. Remove /var/lib/mysql/ib*
  9. Comment out innodb_force_recovery in /etc/my.cnf
  10. Restart mysqld. Look at mysql error log. By default it should be /var/lib/mysql/server/hostname.com.err to see how it creates new ib* files.
  11. Restore databases from the dump: mysql < dump.sql

Solution 2:

I was facing this same error while using mysql:5.7 docker image. Main mistake was trying to create root user which exists by default. More information: https://github.com/docker-library/mysql/issues/129

As given in the above link, solution was to NOT set MYSQL_USER and MYSQL_PASSWORD in the environment variables while starting the docker image.