|-转 Linux下mysql5.7忘记root密码的解决方法
一、首先更改my.cnf的配置文件,并重启mysql
在my.cnf文件中的[mysqld] 下加入下面一行,其余不做改变。
[root@localhost ~]# vim /etc/my.cnf
[mysqld]
skip-grant-tables
[root@localhost ~]# systemctl restart mysqld
二、登录MySQL,此时不需要输入密码,直接回车即可
mysql -uroot -p
三、切换到mysql数据库,查询user表的结构,这里有需要的字段。
在MySQL5.7版本中mysql数据库下已经没有password这个字段了,password字段改成了authentication_string字段。
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> desc user;
+------------------------+-----------------------------------+------+-----+-----------------------+------- +
| Field | Type | Null | Key | Default | Extra
|+------------------------+-----------------------------------+------+-----+-----------------------+------- +
| Host | char(60) | NO | PRI | |
|| User | char(32) | NO | PRI | |
|| Select_priv | enum(N,Y) | NO | | N |
|| Insert_priv | enum(N,Y) | NO | | N |
|| Update_priv | enum(N,Y) | NO | | N |
|| Delete_priv | enum(N,Y) | NO | | N |
|| Create_priv | enum(N,Y) | NO | | N |
|| Drop_priv | enum(N,Y) | NO | | N |
|| Reload_priv | enum(N,Y) | NO | | N |
|| Shutdown_priv | enum(N,Y) | NO | | N |
|| Process_priv | enum(N,Y) | NO | | N |
|| File_priv | enum(N,Y) | NO | | N |
|| Grant_priv | enum(N,Y) | NO | | N |
|| References_priv | enum(N,Y) | NO | | N |
|| Index_priv | enum(N,Y) | NO | | N |
|| Alter_priv | enum(N,Y) | NO | | N |
|| Show_db_priv | enum(N,Y) | NO | | N |
|| Super_priv | enum(N,Y) | NO | | N |
|| Create_tmp_table_priv | enum(N,Y) | NO | | N |
|| Lock_tables_priv | enum(N,Y) | NO | | N |
|| Execute_priv | enum(N,Y) | NO | | N |
|| Repl_slave_priv | enum(N,Y) | NO | | N |
|| Repl_client_priv | enum(N,Y) | NO | | N |
|| Create_view_priv | enum(N,Y) | NO | | N |
|| Show_view_priv | enum(N,Y) | NO | | N |
|| Create_routine_priv | enum(N,Y) | NO | | N |
|| Alter_routine_priv | enum(N,Y) | NO | | N |
|| Create_user_priv | enum(N,Y) | NO | | N |
|| Event_priv | enum(N,Y) | NO | | N |
|| Trigger_priv | enum(N,Y) | NO | | N |
|| Create_tablespace_priv | enum(N,Y) | NO | | N |
|| ssl_type | enum(,ANY,X509,SPECIFIED) | NO | | |
|| ssl_cipher | blob | NO | | NULL |
|| x509_issuer | blob | NO | | NULL |
|| x509_subject | blob | NO | | NULL |
|| max_questions | int(11) unsigned | NO | | 0 |
|| max_updates | int(11) unsigned | NO | | 0 |
|| max_connections | int(11) unsigned | NO | | 0 |
|| max_user_connections | int(11) unsigned | NO | | 0 |
|| plugin | char(64) | NO | | mysql_native_password |
|| authentication_string | text | YES | | NULL |
|| password_expired | enum(N,Y) | NO | | N |
|| password_last_changed | timestamp | YES | | NULL |
|| password_lifetime | smallint(5) unsigned | YES | | NULL |
|| account_locked | enum(N,Y) | NO | | N |
|+------------------------+-----------------------------------+------+-----+-----------------------+------- +
45 rows in set (0.00 sec)
把这个复制下来,修改密码时会用到,当然也可以手打。 ...
浏览更多内容请先登录。
立即注册
分享的网址网站均收集自搜索引擎以及互联网,非查问网运营,查问网并没有提供其服务,请勿利用其做侵权以及违规行为。
更新于:2022-06-15 00:10:31
相关内容
Linux脚本和脚本知识
一键安装TiDB开发环境(centos7)
Mysql错误1366的解决办法:Incorrect string value: '\xF0\x9F...' for ...
关于四字节字符入库时错误的解决方案(Incorrect string value: '\xF0\x9F...
Yii2测了下全文索引,好像是
Call to undefined function mysql_connect() 解决方法汇总
查询linux的ftp的用户名和密码
推荐内容