您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

mysql误删root用户恢复方法

2025/6/3 17:30:52发布15次查看
装完数据库清理一些默认账号的时候不小心把root删除了,flush privileges 之后的新 root 忘了grant任何权限,查看mysqld选项里面有个 skip-grant-tables 代码如下: #/usr/libexec/mysqld --verbos --help mysql5.5手册说明如下 代码如下: --skip-grant-table
装完数据库清理一些默认账号的时候不小心把root删除了,flush privileges 之后的新 root 忘了grant任何权限,查看mysqld选项里面有个 −−skip-grant-tables
代码如下:
#/usr/libexec/mysqld --verbos --help
mysql5.5手册说明如下
代码如下:
--skip-grant-tables
this option causes the server to start without using the privilege system at all, which gives anyone with access to the server unrestricted access to all databases. you can cause a running server to start using the grant tables again by executing mysqladmin flush-privileges or mysqladmin reload command from a system shell, or by issuing a mysql flush privileges statement after connecting to the server. this option also suppresses loading of plugins, user-defined functions (udfs), and scheduled events. to cause plugins to be loaded anyway, use the --plugin-load option.
--skip-grant-tables is unavailable if mysql was configured with the --disable-grant-options option. see section 2.10.2, “typical configure options”.
mysqld_safe是unix/linux系统下的mysql服务器的一个启动脚本。这个脚本增加了一些安全特性,会在启动mysql服务器以后继续监控其运行情况,并在出现错误的时候重新启动服务器。后台启动mysql
代码如下:
#mysqld_safe --skip-grant-tables &
如果没有root账户就添加一个
代码如下:
insert into user set user='root',host='localhost',ssl_cipher='',x509_issuer='',x509_subject='';
直接输入mysql连接并添加权限,这时候是不能使用grant命令的,只能用update
代码如下:
update user set select_priv='y',insert_priv='y',update_priv='y',delete_priv='y',create_priv='y',drop_priv='y',reload_priv='y',shutdown_priv='y',process_priv='y',file_priv='y',grant_priv='y',references_priv='y',index_priv='y',alter_priv='y',show_db_priv='y',super_priv='y',create_tmp_table_priv='y',lock_tables_priv='y',execute_priv='y',repl_slave_priv='y',repl_client_priv='y',create_view_priv='y',show_view_priv='y',create_routine_priv='y',alter_routine_priv='y', create_user_priv='y',event_priv='y',trigger_priv='y',create_tablespace_priv='y',authentication_string='' where user='root';
注意我用的是mysql是5.5版本,可能操作过程中sql语句或其他地方有不同,,语句执行完毕之后需要flush privileges ,还可能要重新登录才行。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product