Linux处理方法
先停止mysql服务:
/etc/init.d/mysql stop
免去权限验证,启动mysql daemon服务(本文以mysql安装到/usr/local/mysql/bin为例):
/usr/local/mysql/bin/mysqld_safe --skip-grant-tables &
登录:
mysql -uroot
修改root帐号密码(请一行一行输入):
use mysql; update user set password=password('123456') where user='root'; flush privileges; quit;
重启mysql即可。
------------------------------华丽分割线------------------------------
Windows处理方法
先停止mysql服务(以管理员身份运行命令提示符CMD):
net stop mysql
进入mysql安装目录,本例以F:\MySQL\MySQL Server 5.1\bin为例:
cd /d F:\MySQL\MySQL Server 5.1\bin
启动mysql:
mysqld --skip-grant-tables
开启新的命令提示符CMD窗口,登录mysql:
mysql -uroot
登录后显示:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.1.58-community MySQL Community Server (GPL)Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL v2 licenseType 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
在此提示符下输入:
update mysql.user set password=password('123456') where user='root';
输入完会有类似提示:
Query OK, 0 rows affected (0.00 sec)
Rows matched: 1 Changed: 0 Warnings: 0
刷新一下数据库:
flush privileges;
结果输出:
Query OK, 0 rows affected (0.00 sec)