今天在安装完mysql后,准备对root加上密码,于是凭着记忆在命令行上打出:
mysql>update user set password='123456' where user='root'<pre name="code" class="sql">mysql>flush privileges;
然后就。。没有然后了。你懂的。为啥?因为漏了打PASSWORD函数对密码加密了
输入命令./bin/mysql进行登陆后show databases;已经看不到系统表,用select user()命令查看结果“root@localhost",霸气啊,怎么root还能登?想想哪里不对,重新用”select current_user(); 查看,果然很悲催的发现是" @localhost"。尝试用./bin/mysql -u root -p登陆发现无论怎么输密码都没效,同时登进去还是空白帐号。
然后网上搜索了一下,发现在localhost上还是有救的。
跟我来做,佛楼米:
1、首先干掉mysql进程 #killall mysqld
2、跳过授权限启动mysql #bin/mysqld_safe --skip-grant-tables
3、重新置入root密码:这次千万不能忘记打password了
mysql>update user set password=password("new_pass") where user="root"<pre name="code" class="sql">mysql>flush privileges;
mysql>exit;
4、重新启动mysql
#killall mysql
#/etc/init.d/mysql.server start
5、然后就可以用./bin/mysql -u root -p登陆吧。