Mysql鬧鬼!不要密碼也能登陸

 
 
有一臺mysql,是之前別人已經裝好的
現在要爲它增加一臺從服務器
在主這臺機器上直接輸入mysql命令回車就可以進
[root@localhost ~]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 111350
Server version: 5.0.67-community-log MySQL Community Edition (GPL)
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql>
 
但是我在新建的從機器上卻不行,提示密碼錯誤
[root@localhost ~]# mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
 
看一下mysql.user表裏面的內容,比較亂
| localhost | root | *DSADRSADFASDFASF23R123 |
| 127.0.0.1 | root | |
我就一個個刪,直到mysql的user表裏面只有
| localhost | root | *DSADRSADFASDFASF23R123 |
但是到主上仍然是直接輸入個mysql就登陸進去了
 
真是靈異啊!!!!
到羣裏面求助
喜歡簡單 說:
skip-grant-tables是不是有這個啊
看看my.cnf裏面是不是把密碼寫進去了
所以按照這個排查
1.查看進程
root 3594 1 0 2009 ? 00:00:00 /bin/sh /usr/bin/mysqld_safe --datadir=/var/lib/mysql --pid-file=/var/lib/mysql/localhost.pid
mysql 3629 3594 1 2009 ? 1-15:12:49 /usr/sbin/mysqld --basedir=/ --datadir=/var/lib/mysql --user=mysql --pid-file=/var/lib/mysql/DBs1.pid --skip-external-locking --port=3306 --socket=/var/lib/mysql/mysql.sock
並沒有skip-grant-tables選項
2.查看/etc/my.cnf
裏面也沒有skip-grant-tables和密碼
 
真是不可理解啊…沒招了
 
因爲都是rpm安裝的,走投無路了就點開了服務的啓動腳本/etc/init.d/mysql
看到下面一段
# If you install MySQL on some other places than /, then you
# have to do one of the following things for this script to work:
#
# - Run this script from within the MySQL installation directory
# - Create a /etc/my.cnf file with the following information:
# [mysqld]
# basedir=<path-to-mysql-installation-directory>
# - Add the above to any other configuration file (for example ~/.my.ini)
# and copy my_print_defaults to /usr/bin
# - Add the path to the mysql-installation-directory to the basedir variable
# below.
#
# If you want to affect other MySQL variables, you should make your changes
# in the /etc/my.cnf, ~/.my.cnf or other MySQL configuration files.
原來~/.my.cnf也可以定義配置的,之前還真沒注意過
 
登到主這臺機器上
[root@localhost ~]# less .my.cnf
[client]
user=root
password=xxxx
果然如此!!!
 
後續討論(不保證準確性和正確性)
yahoon 說:
mysql客戶端登錄的時候首先用/etc/my.cnf的選項,然後看~/.my.cnf
我估計是這麼回事
所以你可以對不同的用戶在此定義用戶密碼其他的選項 ,然後用戶直接輸入mysql就登錄進去了不需要知道密碼
我這直接回車是用我的linux用戶名登錄
喜歡簡單 說:
你可以把.my.cnf拷貝到你的目錄下
以後不用root身份 也可以
~/.my.cnf相當於是/etc/my.cnf的個人用戶版。
是的,我從來不用root,root用戶直接passwd -l鎖掉的
mysqldump和其他命令應該也一樣吧
mysqld肯定不會,其他應該都一樣。
 
感謝羣友的幫助
最後還要感謝秋香http://sery.blog.51cto.com
前幾天秋香還跟我說的my.cnf是選項文件,現在瞭解了點
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章