How to recover/recreate mysql's default 'mysql' database

If you are still able to log in (I assume you aren't since there's no user table) and have databases to save, dump them with

mysqldump --routines databasename > outfile.sql

The MySQL database can be recreated with the command

# Most MySQL versions
mysql_install_db

# MySQL 5.7 and later
mysqld --initialize

MySQL Documentation here


read more at: https://dev.mysql.com/doc/refman/5.7/en/data-directory-initialization.html

On Windows, use one of these commands:

C:\> bin\mysqld --initialize
C:\> bin\mysqld --initialize-insecure

I recently installed mysql 8 and it seemed that there was a problem with mysql default databases. Anyway, this worked for me :

mysql_upgrade -u root -p

Tags:

Mysql