mysql root密碼忘記重置

mysql root密碼忘記mysql

一、啓動時加上下面參數:git

--skip-grant-tablessql

/etc/rc.d/init.d/mysqld start --skip-grant-tables數據庫

二、操做my.conf,增長下面參數ide

[root@host]# cat /etc/my.cnf | grep -v '^$' | grep -v "^#"gitlab

[mysqld]spa

skip-grant-tablesip

重啓mysql服務就能夠登陸mysql了。string


查看mysql的用戶受權:it

mysql> select user,host from mysql.user;

+--------+------+

| user | host |

+--------+------+

| gitlab | % |

| root | % |

+--------+------+

2 rows in set (0.00 sec)


刪除空用戶:

delete from mysq.user where user='';


刪除test庫:

drop database test;


修改mysql密碼報錯:

mysql> update user set password=password(‘redhat’) where user='root';

ERROR 1054 (42S22): Unknown column 'password' in 'field list'


正確改密碼語句:

mysql> update user set authentication_string=password('redhat') where user='root';

Query OK, 1 row affected, 1 warning (0.00 sec)

Rows matched: 1 Changed: 1 Warnings: 1


報錯緣由:

mysql> select version();

+------------+

| version() |

+------------+

| 5.7.24-log |

+------------+

1 row in set (0.00 sec)


想要查看數據庫中用戶信息,結果報錯沒有password這個字段了。原來在mysql5.7及以上的版本里面,password這個字段已經被authentication_string取代。


mysql> desc user;

blob.png

相關文章
相關標籤/搜索