亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

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

標簽:
MySQL


yahoon@2010-5-13

 

有一台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是不是有这个啊

[email protected] 说:

看看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就登录进去了不需要知道密码

[email protected] 说:

我这直接回车是用我的linux用户名登录

喜欢简单 说:

你可以把.my.cnf拷贝到你的目录下

以后不用root身份 也可以

[email protected] 说:

~/.my.cnf相当于是/etc/my.cnf的个人用户版。

[email protected] 说:

是的,我从来不用root,root用户直接passwd -l锁掉的

mysqldump和其他命令应该也一样吧

mysqld肯定不会,其他应该都一样。

 

感谢群友的帮助

最后还要感谢秋香http://sery.blog.51cto.com

前几天秋香还跟我说的my.cnf是选项文件,现在了解了点

©著作权归作者所有:来自51CTO博客作者yahoon的原创作品,如需转载,请注明出处,否则将追究法律责任

密码Mysql数据库mysql


點擊查看更多內容
TA 點贊

若覺得本文不錯,就分享一下吧!

評論

作者其他優質文章

正在加載中
  • 推薦
  • 評論
  • 收藏
  • 共同學習,寫下你的評論
感謝您的支持,我會繼續努力的~
掃碼打賞,你說多少就多少
贊賞金額會直接到老師賬戶
支付方式
打開微信掃一掃,即可進行掃碼打賞哦
今天注冊有機會得

100積分直接送

付費專欄免費學

大額優惠券免費領

立即參與 放棄機會
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號

舉報

0/150
提交
取消