所以我只是在脚下开枪,觉得自己像个白痴。我正在玩我的MySQL数据库授予和撤销权限,同时在我的一个数据库中添加user
表。无论如何,我犯了错误:
Drop table user;
使用我的MySQL服务器管理员帐户而不是主MySQL数据库上的特定于数据库的管理员帐户,并将autocommit设置为true。当然,我得到的错误如下:
SQL Error: Table 'mysql.user' doesn't exist
我还没有设置任何数据库,所以这不是太大的交易,但有没有办法我可以运行create table user ..
语句来恢复我的用户表,或者我应该咬一下子弹并重新安装我的MySQL服务器?
谢谢!
更新
这是我能够用来获取mysql.user
表的创建脚本。我需要在运行此脚本后手动创建用户,但我的root用户仍然在那里并且可以访问数据库。不用说,我的下一个任务是为我的MySQL服务器安排备份任务:)
CREATE TABLE `user` (
`Host` char(60) COLLATE utf8_bin NOT NULL DEFAULT '',
`User` char(16) COLLATE utf8_bin NOT NULL DEFAULT '',
`Password` char(41) CHARACTER SET latin1 COLLATE latin1_bin NOT NULL DEFAULT '',
`Select_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
`Insert_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
`Update_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
`Delete_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
`Create_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
`Drop_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
`Reload_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
`Shutdown_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
`Process_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
`File_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
`Grant_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
`References_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
`Index_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
`Alter_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
`Show_db_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
`Super_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
`Create_tmp_table_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
`Lock_tables_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
`Execute_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
`Repl_slave_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
`Repl_client_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
`Create_view_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
`Show_view_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
`Create_routine_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
`Alter_routine_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
`Create_user_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
`Event_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
`Trigger_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
`Create_tablespace_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
`ssl_type` enum('','ANY','X509','SPECIFIED') CHARACTER SET utf8 NOT NULL DEFAULT '',
`ssl_cipher` blob NOT NULL,
`x509_issuer` blob NOT NULL,
`x509_subject` blob NOT NULL,
`max_questions` int(11) unsigned NOT NULL DEFAULT '0',
`max_updates` int(11) unsigned NOT NULL DEFAULT '0',
`max_connections` int(11) unsigned NOT NULL DEFAULT '0',
`max_user_connections` int(11) unsigned NOT NULL DEFAULT '0',
`plugin` char(60) COLLATE utf8_bin NOT NULL DEFAULT '',
`authentication_string` text COLLATE utf8_bin NOT NULL,
PRIMARY KEY (`Host`,`User`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='Users and global
privileges'
答案 0 :(得分:4)
取决于“让我的用户表回来”的意思。您绝对可以使用相同的模式等创建相同的user
表,但原始表中的任何数据都已永久丢失。当你创建新表时,它不会再次出现,抱歉。
值得庆幸的是,不要求您重新安装MySQL服务器或其他任何东西。服务器很好;你刚丢了一张桌子。删除表不会以任何方式损害服务器。重新创建它,你很高兴。 (如果你没有表格结构的记录,那么,我相信你可以搞清楚。)如果你有备份,还原它们。如果没有,那么,我猜你将从现在开始备份。
抱歉,您遇到了麻烦,希望您将来能够避免这样的麻烦。祝你好运!
答案 1 :(得分:2)
没有合理的方法来恢复你的桌子,你真的不需要。如果您想要保存在其他数据库中的数据,请遵循这些简单的说明。 (Paths假定标准的linux安装。不要只是在运行之前复制粘贴,读取,解释,理解每个命令)。此外,这一切都来自记忆,我还没有测试过这一点。
停止你的mysql服务器进程
cd /var/lib/
mv mysql/mysql mysql/old_mysql_db
mv mysql mysql_save
mkdir mysql
chown --reference=mysql_save mysql
chmod --reference=mysql_save mysql
mysql_install_db
mv mysql/mysql mysql_save/
mv mysql ~/mysql_newinstall_deleteme
mv mysql_save mysql
现在启动你的mysql服务器进程,然后回到它。您将从头开始使用您的所有用户和权限,但您的其他数据库应该完好无损,假设您的mysql数据库没有使用innodb。
答案 2 :(得分:0)
如果从备份中导入旧用户表然后拒绝升级,则这是包含45列的最新表。
CREATE TABLE `user` (
`Host` CHAR(60) NOT NULL DEFAULT '' COLLATE 'utf8_bin',
`User` CHAR(32) NOT NULL DEFAULT '' COLLATE 'utf8_bin',
`Select_priv` ENUM('N','Y') NOT NULL DEFAULT 'N' COLLATE 'utf8_general_ci',
`Insert_priv` ENUM('N','Y') NOT NULL DEFAULT 'N' COLLATE 'utf8_general_ci',
`Update_priv` ENUM('N','Y') NOT NULL DEFAULT 'N' COLLATE 'utf8_general_ci',
`Delete_priv` ENUM('N','Y') NOT NULL DEFAULT 'N' COLLATE 'utf8_general_ci',
`Create_priv` ENUM('N','Y') NOT NULL DEFAULT 'N' COLLATE 'utf8_general_ci',
`Drop_priv` ENUM('N','Y') NOT NULL DEFAULT 'N' COLLATE 'utf8_general_ci',
`Reload_priv` ENUM('N','Y') NOT NULL DEFAULT 'N' COLLATE 'utf8_general_ci',
`Shutdown_priv` ENUM('N','Y') NOT NULL DEFAULT 'N' COLLATE 'utf8_general_ci',
`Process_priv` ENUM('N','Y') NOT NULL DEFAULT 'N' COLLATE 'utf8_general_ci',
`File_priv` ENUM('N','Y') NOT NULL DEFAULT 'N' COLLATE 'utf8_general_ci',
`Grant_priv` ENUM('N','Y') NOT NULL DEFAULT 'N' COLLATE 'utf8_general_ci',
`References_priv` ENUM('N','Y') NOT NULL DEFAULT 'N' COLLATE 'utf8_general_ci',
`Index_priv` ENUM('N','Y') NOT NULL DEFAULT 'N' COLLATE 'utf8_general_ci',
`Alter_priv` ENUM('N','Y') NOT NULL DEFAULT 'N' COLLATE 'utf8_general_ci',
`Show_db_priv` ENUM('N','Y') NOT NULL DEFAULT 'N' COLLATE 'utf8_general_ci',
`Super_priv` ENUM('N','Y') NOT NULL DEFAULT 'N' COLLATE 'utf8_general_ci',
`Create_tmp_table_priv` ENUM('N','Y') NOT NULL DEFAULT 'N' COLLATE 'utf8_general_ci',
`Lock_tables_priv` ENUM('N','Y') NOT NULL DEFAULT 'N' COLLATE 'utf8_general_ci',
`Execute_priv` ENUM('N','Y') NOT NULL DEFAULT 'N' COLLATE 'utf8_general_ci',
`Repl_slave_priv` ENUM('N','Y') NOT NULL DEFAULT 'N' COLLATE 'utf8_general_ci',
`Repl_client_priv` ENUM('N','Y') NOT NULL DEFAULT 'N' COLLATE 'utf8_general_ci',
`Create_view_priv` ENUM('N','Y') NOT NULL DEFAULT 'N' COLLATE 'utf8_general_ci',
`Show_view_priv` ENUM('N','Y') NOT NULL DEFAULT 'N' COLLATE 'utf8_general_ci',
`Create_routine_priv` ENUM('N','Y') NOT NULL DEFAULT 'N' COLLATE 'utf8_general_ci',
`Alter_routine_priv` ENUM('N','Y') NOT NULL DEFAULT 'N' COLLATE 'utf8_general_ci',
`Create_user_priv` ENUM('N','Y') NOT NULL DEFAULT 'N' COLLATE 'utf8_general_ci',
`Event_priv` ENUM('N','Y') NOT NULL DEFAULT 'N' COLLATE 'utf8_general_ci',
`Trigger_priv` ENUM('N','Y') NOT NULL DEFAULT 'N' COLLATE 'utf8_general_ci',
`Create_tablespace_priv` ENUM('N','Y') NOT NULL DEFAULT 'N' COLLATE 'utf8_general_ci',
`ssl_type` ENUM('','ANY','X509','SPECIFIED') NOT NULL DEFAULT '' COLLATE 'utf8_general_ci',
`ssl_cipher` BLOB NOT NULL,
`x509_issuer` BLOB NOT NULL,
`x509_subject` BLOB NOT NULL,
`max_questions` INT(11) UNSIGNED NOT NULL DEFAULT '0',
`max_updates` INT(11) UNSIGNED NOT NULL DEFAULT '0',
`max_connections` INT(11) UNSIGNED NOT NULL DEFAULT '0',
`max_user_connections` INT(11) UNSIGNED NOT NULL DEFAULT '0',
`plugin` CHAR(64) NOT NULL DEFAULT 'mysql_native_password' COLLATE 'utf8_bin',
`authentication_string` TEXT NULL COLLATE 'utf8_bin',
`password_expired` ENUM('N','Y') NOT NULL DEFAULT 'N' COLLATE 'utf8_general_ci',
`password_last_changed` TIMESTAMP NULL DEFAULT NULL,
`password_lifetime` SMALLINT(5) UNSIGNED NULL DEFAULT NULL,
`account_locked` ENUM('N','Y') NOT NULL DEFAULT 'N' COLLATE 'utf8_general_ci',
PRIMARY KEY (`Host`, `User`)
)
COMMENT='Users and global privileges'
COLLATE='utf8_bin'
ENGINE=MyISAM
;
和默认用户数据:
INSERT INTO
user
(Host
, User
, Select_priv
, Insert_priv
, Update_priv
, Delete_priv
, Create_priv
, Drop_priv
, Reload_priv
, Shutdown_priv
, Process_priv
, File_priv
, Grant_priv
, References_priv
, Index_priv
, Alter_priv
, Show_db_priv
, Super_priv
, Create_tmp_table_priv
, Lock_tables_priv
, Execute_priv
, Repl_slave_priv
, Repl_client_priv
, Create_view_priv
, Show_view_priv
, Create_routine_priv
, Alter_routine_priv
, Create_user_priv
, Event_priv
, Trigger_priv
, Create_tablespace_priv
, ssl_type
, ssl_cipher
, x509_issuer
, x509_subject
, max_questions
, max_updates
, max_connections
, max_user_connections
, plugin
, authentication_string
, password_expired
, password_last_changed
, password_lifetime
, account_locked
)
VALUES ('localhost', 'root', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', '', '', '', '', 0, 0, 0, 0, 'mysql_native_password', '', 'N', '2018-04-20 14:57:25', NULL, 'N');
INSERT INTO user_copy
(Host
, User
, Select_priv
, Insert_priv
, Update_priv
, Delete_priv
, Create_priv
, Drop_priv
, Reload_priv
, Shutdown_priv
, Process_priv
, File_priv
, Grant_priv
, References_priv
, Index_priv
, Alter_priv
, Show_db_priv
, Super_priv
, Create_tmp_table_priv
, Lock_tables_priv
, Execute_priv
, Repl_slave_priv
, Repl_client_priv
, Create_view_priv
, Show_view_priv
, Create_routine_priv
, Alter_routine_priv
, Create_user_priv
, Event_priv
, Trigger_priv
, Create_tablespace_priv
, ssl_type
, ssl_cipher
, x509_issuer
, x509_subject
, max_questions
, max_updates
, max_connections
, max_user_connections
, plugin
, authentication_string
, password_expired
, password_last_changed
, password_lifetime
, account_locked
)
VALUES ('localhost', 'mysql.session', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'Y', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', '', '', '', '', 0, 0, 0, 0, 'mysql_native_password', '*THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE', 'N', '2018-04-20 14:57:25', NULL, 'Y');
INSERT INTO user_copy
(Host
, User
, Select_priv
, Insert_priv
, Update_priv
, Delete_priv
, Create_priv
, Drop_priv
, Reload_priv
, Shutdown_priv
, Process_priv
, File_priv
, Grant_priv
, References_priv
, Index_priv
, Alter_priv
, Show_db_priv
, Super_priv
, Create_tmp_table_priv
, Lock_tables_priv
, Execute_priv
, Repl_slave_priv
, Repl_client_priv
, Create_view_priv
, Show_view_priv
, Create_routine_priv
, Alter_routine_priv
, Create_user_priv
, Event_priv
, Trigger_priv
, Create_tablespace_priv
, ssl_type
, ssl_cipher
, x509_issuer
, x509_subject
, max_questions
, max_updates
, max_connections
, max_user_connections
, plugin
, authentication_string
, password_expired
, password_last_changed
, password_lifetime
, account_locked
)
VALUES ('localhost', 'mysql.sys', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', '', '', '', '', 0, 0, 0, 0, 'mysql_native_password', '*THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE', 'N', '2018-04-20 14:57:25', NULL, 'Y');