为了账号安全,请及时绑定邮箱和手机立即绑定

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

realzyy@gmail.com 说:

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

walkerxk@gmail.com 说:

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

喜欢简单 说:

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

以后不用root身份 也可以

walkerxk@gmail.com 说:

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

walkerxk@gmail.com 说:

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

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

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

 

感谢群友的帮助

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

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

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

密码Mysql数据库mysql


点击查看更多内容
TA 点赞

若觉得本文不错,就分享一下吧!

评论

作者其他优质文章

正在加载中
  • 推荐
  • 评论
  • 收藏
  • 共同学习,写下你的评论
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦
今天注册有机会得

100积分直接送

付费专栏免费学

大额优惠券免费领

立即参与 放弃机会
意见反馈 帮助中心 APP下载
官方微信

举报

0/150
提交
取消