解決mysql“Access denied for user 'root'

 大致意思就是給mysql中的root用戶添加密碼 (密碼我就用******表示)

[ooo@localhost ~]$ mysqladmin -u root -p ******
Enter password:
mysqladmin: connect to server at 'localhost' failed
error: 'Access denied for user 'root'@'localhost' (using password: YES)'

[ooo@localhost ~]$ sudo /etc/init.d/mysqld stop
停止 MySQL: [確定]
相反就是啓動

[ooo@localhost ~]$ sudo mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
[1] 17641

[ooo@localhost ~]$ nohup: ignoring input and redirecting stderr to stdout
Starting mysqld daemon with databases from /var/lib/mysql
mysql -u root mysql (注意這裏要自己輸入 沒提示的)
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 1
Server version: 5.0.67 Source distribution

Type 'help;' or 'h' for help. Type 'c' to clear the buffer.

mysql> UPDATE user SET Password=PASSWORD('******') where USER='root';
Query OK, 3 rows affected (0.02 sec)
Rows matched: 3 Changed: 3 Warnings: 0

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.01 sec)

mysql> quit
Bye


[ooo@localhost ~]$ sudo /etc/init.d/mysqld restart
STOPPING server from pid file /var/run/mysqld/mysqld.pid
081205 12:11:33 mysqld ended

停止 MySQL: [確定]
啓動 MySQL: [確定]
[1]+ Done sudo mysqld_safe --user=mysql --skip-grant-tables --skip-networking
[ooo@localhost ~]$ mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 2
Server version: 5.0.67 Source distribution

Type 'help;' or 'h' for help. Type 'c' to clear the buffer.

mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| test |
+--------------------+
3 rows in set (0.00 sec)

mysql> quit
Bye
[ooo@localhost ~]$
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章