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

mysql user表没有了怎么办

2024/3/31 8:11:59发布16次查看
mysql user表没有了的解决办法:1、在“[mysqld]”中添加“skip-grant-tables”;2、编辑my.cnf配置文件,添加“sql_mode=no_engine_substitution”;3、重启mysql服务。
本文操作环境:windows7系统,mysql5.5版,dell g3电脑。
mysql user表没有了怎么办?
mysql 忘记密码,重置密码,mysql.user表为空的解决办法:
一、用户表有用户,直接修改密码error 1045 (28000): access denied for user 'root'@'localhost' (using password: yes)
修改mysql配置文件my.cnf:
vim /etc/my.cnf
在[mysqld]中添加
skip-grant-tables
重启mysql服务,用空密码直接登录,查询用户表,有结果则按如下步骤修改,结果为空直接最后的解决办法
mysql> select host,user,authentication_string from mysql.user;+-----------+---------------+-------------------------------------------+| host      | user          | authentication_string                     |+-----------+---------------+-------------------------------------------+| localhost | root          | *6a7a490fb9dc8c33c2b025a91737077a7e9cc5e5 || localhost | mysql.session | *thisisnotavalidpasswordthatcanbeusedhere || localhost | mysql.sys     | *thisisnotavalidpasswordthatcanbeusedhere || %         | root          | *6a7a490fb9dc8c33c2b025a91737077a7e9cc5e5 |+-----------+---------------+-------------------------------------------+4 rows in set (0.00 sec)
修改对应用户的密码
# 重置密码为 123456mysql> update mysql.user set authentication_string=password('123456') where user='root' query ok, 2 rows affected, 1 warning (0.00 sec)rows matched: 2  changed: 2  warnings: 1# 刷新权限,使配置生效mysql> flush privileges;query ok, 0 rows affected (0.00 sec)# 退出mysql> quitbye
取消或注释掉my.cnf配置文件添加的选项 skip-grant-tables ,重启mysql服务,搞定收工。
二、用户表没有数据,则需要插入用户数据mysql> select host,user,authentication_string from mysql.user;empty set (0.00 sec)# 退出登陆mysql> exitbye
编辑my.cnf配置文件,添加或修改下面两项(我这没有sql_mode项):
sql_mode=no_engine_substitutionskip-grant-tables
停止mysql服务,启动数据库的安全模式:mysqld_safe &使用root 空密码连接数据库: mysql -uroot -p插入root用户数据
mysql> insert into mysql.user(host,user,authentication_string) values(%,root,password(123456)); query ok, 1 row affected, 4 warnings (0.00 sec)
再次查询mysql.user表,会报错
mysql> select host,user,authentication_string from mysql.user;error 1194 (hy000): table 'user' is marked as crashed and should be repaired
需要修复mysql.user表
mysql> repair table mysql.user;+------------+--------+----------+-------------------------------------------------+| table      | op     | msg_type | msg_text                                        |+------------+--------+----------+-------------------------------------------------+| mysql.user | repair | info     | wrong bytesec: 113-108- 95 at 396; skipped      || mysql.user | repair | info     | found block that points outside data file at 32 || mysql.user | repair | info     | found block that points outside data file at 36 || mysql.user | repair | info     | found block that points outside data file at 40 || mysql.user | repair | info     | found block that points outside data file at 44 || mysql.user | repair | info     | found block that points outside data file at 48 || mysql.user | repair | info     | found block that points outside data file at 52 || mysql.user | repair | info     | found block that points outside data file at 56 || mysql.user | repair | info     | found block that points outside data file at 60 || mysql.user | repair | warning  | number of rows changed from 4 to 3              || mysql.user | repair | status   | ok                                              |+------------+--------+----------+-------------------------------------------------+11 rows in set (0.64 sec)# 再次查询user表mysql> select host,user,authentication_string from mysql.user;+-----------+---------------+-------------------------------------------+| host      | user          | authentication_string                     |+-----------+---------------+-------------------------------------------+| localhost | mysql.session | *thisisnotavalidpasswordthatcanbeusedhere || localhost | mysql.sys     | *thisisnotavalidpasswordthatcanbeusedhere || %         | root          | *6bb4837eb74329105ee4568dda7dc67ed2ca2ad9 |+-----------+---------------+-------------------------------------------+3 rows in set (0.00 sec)
修改root用户的权限:
  update mysql.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'   where user='root';# 更新权限mysql> flush privileges;query ok, 0 rows affected (0.00 sec)# 退出登陆mysql> exitbye
退出mysql,将my.cnf配置文件的修改恢复结束mysqld_safe 进程:pkill mysql启动mysql服务: systemctl start mysql
问题解决!
推荐学习:《mysql视频教程》
以上就是mysql user表没有了怎么办的详细内容。
该用户其它信息

VIP推荐

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