#mysql錯誤:(密碼不正確,須要重置密碼)mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
#編輯配置文件sql
[root@m1 mysql]# vi /roobo/server/mysql/my.cnf數據庫
[mysqld]bash
skip-grant-tables ide
#修改完後重啓服務ui
[root@m1 mysql]# /etc/init.d/mysqld restartspa
#登陸數據庫rest
[root@m1 mysql]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.24-log Source distributioncode
Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.server
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>
mysql> use mysql;
mysql> update user set password=password("你的新密碼") where user="root";
mysql> flush privileges;
mysql> quit
#再把vi my.cnf 配置文件中下面參數刪除。
[mysqld]
skip-grant-tables
#修改完後重啓服務
[root@m1 mysql]# /etc/init.d/mysqld restart
#再用設置的密碼登陸
mysql -uroot -p
passwd:******
mysql error 1044(42000)錯誤
[root@m1 ~]# mysql -uroot -p
Enter password:
ERROR 1049 (42000): Unknown database '127.0.0.1'
[root@m1 ~]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 18
Server version: 5.6.24-log Source distribution
Copyright (c) 2000, 2015, 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> grant all on work.* to work@'192.168.1.4' identified by 'juan3652014';
ERROR 1044 (42000): Access denied for user 'root'@'localhost' to database 'work'
緣由: 受權須要WITH GRANT OPTION 才能受權,不然會報。
mysql> show grants for root@'localhost';
+----------------------------------------------------------------------------------------------------------------------+
| Grants for root@localhost |
+----------------------------------------------------------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY PASSWORD '*F109C974766912D490ECD7E3C8754542FC773A49' |
| GRANT PROXY ON ''@'' TO 'root'@'localhost' WITH GRANT OPTION
+----------------------------------------------------------------------------------------------------------------------+
2 rows in set (0.00 sec)
解決方法:
#登陸mysql
mysql -uroot -p -h 127.0.0.1
mysql> use mysql
Database changed
mysql> select user,host from user;
+--------+-------------+
| user | host |
+--------+-------------+
| root | 127.0.0.1 |
| rep | 192.168.1.% |
| work | 192.168.1.4 |
| root | localhost |
| zabbix | localhost |
+--------+-------------+
5 rows in set (0.00 sec)
#受權成功
grant all on work.* to work@'192.168.1.4' identified by 'juan3652014';
flush privileges;
如上所示,root@localhost帳號沒有WITH GRANT OPTION選項,關於WITH GRANT OPTION選項,若是想讓受權的用戶,也能夠將這些權限授予給其餘用戶,須要選項 「WITH GRANT OPTION「 。也就是說有這個選項就能夠將權限傳遞給第三方。這也是上面root@localhost用戶給其它用後受權報錯的緣由,若是以 root@127.0.0.1登陸(此帳號擁有WITHGRANT OPTION選項),建立用戶並受權就不會有這個錯誤。