mysql - I deleted the user table! how can I recover it?

前端 未结 3 722
[愿得一人]
[愿得一人] 2021-01-20 00:58

I sure i deleted the table \'mysql\' in an accident , then have maked this error \"Table mysql.user dosen\'t exist\"

How can i fix it , or create a new table \'mysql

3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-20 01:30

    There is not alot you can do. If you can run queries and have recently backed up the whole database using "BACKUP TABLE", then you can try to run this query:

     RESTORE TABLE mysql.user FROM '/path/to/backup/directory'
    

    If you cannot then you will have to execute mysql with '--skip-grant-tables' option in the command line. This will allow you to atleast gain access. You can also recreate it by running the mysql_install_db command. Found Here

    Either way your table should look like this

     +-----------------+---------------+------+-----+---------+-------+ 
     | Field | Type | Null | Key | Default | Extra | 
     +-----------------+---------------+------+-----+---------+-------+ 
     | Host | varchar(20) | | PRI | | | 
     | User | varchar(6) | | PRI | | | 
     | Password | varchar(41) | | | | | 
     | Select_priv | enum('N','Y') | | | N | | 
     | Insert_priv | enum('N','Y') | | | N | | 
     | Update_priv | enum('N','Y') | | | N | | 
     | Delete_priv | enum('N','Y') | | | N | | 
     | Create_priv | enum('N','Y') | | | N | | 
     | Drop_priv | enum('N','Y') | | | N | | 
     | Reload_priv | enum('N','Y') | | | N | | 
     | Shutdown_priv | enum('N','Y') | | | N | | 
     | Process_priv | enum('N','Y') | | | N | | 
     | File_priv | enum('N','Y') | | | N | | 
     | Grant_priv | enum('N','Y') | | | N | | 
     | References_priv | enum('N','Y') | | | N | | 
     | Index_priv | enum('N','Y') | | | N | | 
     | Alter_priv | enum('N','Y') | | | N | | 
     +-----------------+---------------+------+-----+---------+-------+ 
    

提交回复
热议问题