mysql重置密碼和mysql error 1044(42000)錯誤


#mysql錯誤:(密碼不正確,需要重置密碼)

 ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

#編輯配置文件

[root@m1 mysql]# vi /roobo/server/mysql/my.cnf

[mysqld]

skip-grant-tables  

#修改完后重啟服務

[root@m1 mysql]# /etc/init.d/mysqld restart

#登錄數據庫

[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 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>

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選項),創建用戶並授權就不會有這個錯誤。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM