mysql 多实例登录密码测试
2017-01-31 16:37
351 查看
最近在做mysql 多实例的时候,采用不同的方式登录mysql数据库,发现mysql -uroot -p -h 127.0.0.1 -P3308 ,登录时居然不要密码就可以登录
![](http://img.baidu.com/hi/jx2/j_0064.gif)
,吓得我一身汗,经过检查终于找到原因记录下来,给小白们参考。
![](http://img.baidu.com/hi/jx2/j_0051.gif)
[root@mysql ~]# mysql -uroot -p -S /data/3308/mysql.sock
Enter password: #需要输入密码
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 23
Server version: 5.5.32-log Source distribution
Copyright (c) 2000, 2013, 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> select current_user();
+----------------+
| current_user() |
+----------------+
| root@localhost |
+----------------+
1 row in set (0.00 sec)
*******************************************************************
[root@mysql ~]# mysql -uroot -p -h 127.0.0.1 -P3308
Enter password: #不需要输入密码,直接回车登录
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 24
Server version: 5.5.32-log Source distribution
Copyright (c) 2000, 2013, 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> select current_user();
+----------------+
| current_user() |
+----------------+
| root@127.0.0.1 |
+----------------+
1 row in set (0.00 sec)
不要密码登录原因:
登录数据库查看密码
mysql> select user,host,password from mysql.user;
+------+-----------+-------------------------------------------+
| user | host | password |
+------+-----------+-------------------------------------------+
| root | localhost | *FE28814B4A8B3309DAC6ED7D3237ADED6DA1E515 |
| root | mysql | |
| root | 127.0.0.1 | |
| root | ::1 | |
| | localhost | |
| | mysql | |
| tom | % | *71FF744436C7EA1B954F6276121DB5D2BF68FC07 |
| tom1 | % | *36B46F2410B8A8E6E1DC6952C5C26929FDC07421 |
| tom2 | % | *FEF6FE64F2588DC11E69F0DC5A704E231D1AAEFC |
| tom | localhost | *71FF744436C7EA1B954F6276121DB5D2BF68FC07 |
+------+-----------+-------------------------------------------+
10 rows in set (0.00 sec)
总结:第一种方式登录后,用户是 root@localhost,第二种方式登录后,用户是root@127.0.0.1 查看数据库,发现root@localhost没有设置密码,所以使用第一种方式登录不需要输入密码。
![](http://img.baidu.com/hi/jx2/j_0064.gif)
,吓得我一身汗,经过检查终于找到原因记录下来,给小白们参考。
![](http://img.baidu.com/hi/jx2/j_0051.gif)
[root@mysql ~]# mysql -uroot -p -S /data/3308/mysql.sock
Enter password: #需要输入密码
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 23
Server version: 5.5.32-log Source distribution
Copyright (c) 2000, 2013, 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> select current_user();
+----------------+
| current_user() |
+----------------+
| root@localhost |
+----------------+
1 row in set (0.00 sec)
*******************************************************************
[root@mysql ~]# mysql -uroot -p -h 127.0.0.1 -P3308
Enter password: #不需要输入密码,直接回车登录
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 24
Server version: 5.5.32-log Source distribution
Copyright (c) 2000, 2013, 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> select current_user();
+----------------+
| current_user() |
+----------------+
| root@127.0.0.1 |
+----------------+
1 row in set (0.00 sec)
不要密码登录原因:
登录数据库查看密码
mysql> select user,host,password from mysql.user;
+------+-----------+-------------------------------------------+
| user | host | password |
+------+-----------+-------------------------------------------+
| root | localhost | *FE28814B4A8B3309DAC6ED7D3237ADED6DA1E515 |
| root | mysql | |
| root | 127.0.0.1 | |
| root | ::1 | |
| | localhost | |
| | mysql | |
| tom | % | *71FF744436C7EA1B954F6276121DB5D2BF68FC07 |
| tom1 | % | *36B46F2410B8A8E6E1DC6952C5C26929FDC07421 |
| tom2 | % | *FEF6FE64F2588DC11E69F0DC5A704E231D1AAEFC |
| tom | localhost | *71FF744436C7EA1B954F6276121DB5D2BF68FC07 |
+------+-----------+-------------------------------------------+
10 rows in set (0.00 sec)
总结:第一种方式登录后,用户是 root@localhost,第二种方式登录后,用户是root@127.0.0.1 查看数据库,发现root@localhost没有设置密码,所以使用第一种方式登录不需要输入密码。
相关文章推荐
- 登录多实例MySQL失败,修改密码临时解决,原因不明
- 在SQL Server实例之间传输登录和密码
- 经测试最好用的mysql密码忘记的解决方法
- 修改MySQL密码后导致不能再登录phpmyadmin的解决方法
- CentOS系统找回mysql登录密码
- windows 下 mysql 密码破解实例
- HOW TO:在 SQL Server 实例之间传输登录和密码
- Centos 下找回mysql登录密码
- MySql学习笔记(登录、增加用户、密码更改)
- 如何在实例之间传输登录和密码
- 安装好MySQL后,用SQL去修改root帐号的密码,结果不能登录了!
- HOWTO:在实例之间传输登录和密码
- 安装好MySQL后,用SQL去修改root帐号的密码,结果不能登录了!
- 实例分析mysql用户登录 推荐
- 用phpmyadmin更改mysql5.0登录密码
- [SQL Server 2005/2008]如何在实例之间传输登录和密码
- mysql忘记root登录密码
- 安装好MySQL后,用SQL去修改root帐号的密码,结果不能登录了!
- 经测试最好用的mysql密码忘记的解决方法
- mysql 忘记密码 后的修改测试可用