標籤:多執行個體 mysql 登入失敗 修改密碼 重新整理許可權
昨天學習第11課“主從同步”的視頻(L11-11-MySQL主從同步手把手實戰操作詳解w),再次遇到問題。
[[email protected] ~]# mysql -uroot -p‘oldboy3307‘ -S /data/3307/mysql.sockERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password: YES)
上個月初學習安裝多執行個體的時候,也遇到過這個報錯。查看當時的日記,發現自己整理的文檔也有很多問題。2個月之後再看,發現雖然想記錄的很詳細,但思路還是有些亂。
根據日記裡的記錄:使用如下的命令啟動資料庫服務。
[[email protected] ~]# mysqld_safe --defaults-file=/data/3307/my.cnf --skip-grant-table &[1] 4959140726 19:04:23 mysqld_safe Logging to ‘/data/3307/mysql_oldboy3307.err‘.140726 19:04:23 mysqld_safe Starting mysqld daemon with databases from /data/3307/data
登入資料庫後,使用授權語句竟然報錯。
mysql> GRANT ALL PRIVILEGES ON *.* TO [email protected]"%" IDENTIFIED BY "111";ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement
至今也不明白這個報錯是什麼意思,百度上只是說可以通過重新整理許可權“flush privileges;”解決。
嘗試正常啟動資料庫:
[[email protected] ~]# /data/3307/mysql startStarting MySQL...
使用另外的命令登入資料庫,也是報錯。
[[email protected] ~]# mysql -uroot -p -S /data/3307/mysql.sock -h 127.0.0.1Enter password: ERROR 2003 (HY000): Can‘t connect to MySQL server on ‘127.0.0.1‘ (111)
最後決定,還是直接在資料庫裡把root密碼改了再說。
[[email protected] ~]# mysqld_safe --defaults-file=/data/3307/my.cnf --skip-grant-table &[1] 5535140726 19:15:56 mysqld_safe Logging to ‘/data/3307/mysql_oldboy3307.err‘.140726 19:15:56 mysqld_safe Starting mysqld daemon with databases from /data/3307/data[[email protected] ~]# netstat -lnt|grep 330tcp 0 0 0.0.0.0:3307 0.0.0.0:* LISTEN[[email protected] ~]# mysql -uroot -S /data/3307/mysql.sockWelcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 3Server version: 5.1.62-log Source distributionCopyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.mysql> select user,host,password from mysql.user;+-------+-------------+-------------------------------------------+| user | host | password |+-------+-------------+-------------------------------------------+| root | % | *007FFCA4271EE782CBEE4DB65344C906C10915BB || root | localhost | *007FFCA4271EE782CBEE4DB65344C906C10915BB || root | 127.0.0.1 | *007FFCA4271EE782CBEE4DB65344C906C10915BB || user2 | localhost | *12A20BE57AF67CBF230D55FD33FBAF5230CFDBC4 || rep | 192.168.1.% | *FE28814B4A8B3309DAC6ED7D3237ADED6DA1E515 |+-------+-------------+-------------------------------------------+5 rows in set (0.00 sec)mysql> update mysql.user set password=PASSWORD(‘123456‘) where user=‘root‘;Query OK, 3 rows affected (0.00 sec)Rows matched: 3 Changed: 3 Warnings: 0mysql> quitBye
看到沒有,修改密碼之後我竟然沒有重新整理許可權。結果,登入的時候就容易出現問題。當然,不是一定會出現問題。
我這裡修改密碼為“123456”之後,登入資料庫是沒有問題的。但是,在資料庫裡再次把密碼修改為“oldboy3307”,退出再次登入資料庫,就又報錯了。
把資料庫的root密碼再次修改為“123456”之後,再來一遍:
[[email protected] ~]# mysql -uroot -p‘123456‘ -S /data/3307/mysql.sockWelcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 3Server version: 5.1.62-log Source distributionCopyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.mysql> update mysql.user set password=PASSWORD(‘oldboy3307‘) where user=‘root‘;Query OK, 3 rows affected (0.00 sec)Rows matched: 3 Changed: 3 Warnings: 0mysql> flush privileges;Query OK, 0 rows affected (0.00 sec)mysql> quitBye[[email protected] ~]# mysql -uroot -p‘oldboy3307‘ -S /data/3307/mysql.sockWelcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 4Server version: 5.1.62-log Source distributionCopyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.mysql> quitBye
這次,最後的問題,似乎是沒有重新整理許可權的原因。但是,看起來這又好像只是表象。
剛才登入資料庫還一切正常,為什麼退出之後就不能登入了呢?為什麼修改密碼之後,就又可以登入了呢?為什麼有時候在修改密碼之後,即使沒有重新整理許可權也可以登入資料庫,有時候又不能登入呢?
保留這些問題,慢慢研究。
整理出這個文檔,這是我目前唯一能做的了。
本文出自 “dark-matter” 部落格,請務必保留此出處http://gagarin.blog.51cto.com/1056957/1530937