如果某天发现自己登陆不上mysql,又恰巧记不得密码,那只能通过本地重新修改mysql.user里面的密码。
首先
$ sudo service mysqld stop //确认mysqld和免安装的mysqld都关闭 $ sudo mysqld_safe --skip-grant-table & //进入本地安全模式
到这里后mysql可以直接用root登陆进去不需要密码,接着
mysql>use mysql mysql>SELECT host,user,password,Grant_priv,Super_priv FROM mysql.user; +--------------+---------+-------------------------------------------+------------+------------+ | host | user | password | Grant_priv | Super_priv | +--------------+---------+-------------------------------------------+------------+------------+ | 192.168.28.% | Looft | *FED29C14B2E900D70B11B1F1B370F953BA51A6A0 | N | Y | | 192.168.28.% | live | *FED29C14B2E900D70B11B1F1B370F953BA51A6A0 | N | Y | | 192.168.28.% | root | *FED29C14B2E900D70B11B1F1B370F953BA51A6A0 | Y | Y | | localhost | ranger | wtfwtfwtf | N | N | | localhost | root | 0 | Y | Y | | % | root | *FED29C14B2E900D70B11B1F1B370F953BA51A6A0 | N | Y | | 127.0.0.1 | root | *FED29C14B2E900D70B11B1F1B370F953BA51A6A0 | Y | Y | | % | ranger | *84BB87F6BF7F61703B24CE1C9AA9C0E3F2286900 | N | Y | +--------------+---------+-------------------------------------------+------------+------------+
这里看到ranger@localhost密码有问题,没有权限,没有通过password函数进行加密,跟其他的不一样。于是进行update更改密码并加密
mysql>UPDATE mysql.user SET Grant_priv='Y', Super_priv='Y',Password=password('wtfwtfwtf') WHERE User='ranger' and host='localhost'; mysql>flush privileges;
搞定之后记得关闭mysqld_safe,并开启mysqld进程。
$ sudo mysqladmin -uroot -p***** shutdown $ sudo service mysqld start $ mysql -uranger -pwtfwtfwtf Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 20 Server version: 5.1.73 Source distribution Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql>
测试后ok
新加入规则也很简单
mysql>insert into mysql.user(Host,User,Password) values("127.0.0.1","ranger",Password=password('wtfwtfwtf'));
如对本文有疑问, 点击进行留言回复!!
MySQL-关系代数-并、交、差、等值连接、自然连接、左连接。。。
网友评论