Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

mysql

When I installed mysql it came with two database, mysql and information schema. I accidentally deleted the mysql database. Is there any way I can recreate it?

Also, since it contains a table that contains user information, would there be any way I can view users' information without it?

like image 454
user784637 Avatar asked Jan 18 '12 13:01

user784637


People also ask

How do I restore an existing MySQL database?

In Database Explorer, right-click the server connection on which you want to restore the database and select Backup and Restore > Restore Database. In the Database Restore Wizard, select the backup file and click Restore.


3 Answers

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

like image 140
Michael Berkowski Avatar answered Oct 30 '22 01:10

Michael Berkowski


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
like image 25
hihu Avatar answered Oct 30 '22 03:10

hihu


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
like image 3
Sina Avatar answered Oct 30 '22 02:10

Sina