mysql设置root密码的问题?
背景:
使用root权限登录服务器,安装mysql,使用mysqladmin
给用户名为"root"的user设置密码为xxx
问题:
在原root账号登录服务器的情况下,然后直接使用
mysql
命令不用输密码即可登录mysql;使用用户名为test的私钥登录服务器,有以下几种情况:
1. 直接使用
mysql
命令提示Access denied for user 'test'@'localhost
;
2. 而使用mysql -uroot -pxxx
则提示Access denied for user 'root'@'localhost
;
3. 另外,使用sudo mysql
则成功且不需要输mysql密码
期待结果:
mysql只有一个用户User="root"的情况下,任何账号登录服务器,均需要输入密码才能进入mysql,且不要加sudo
,即类似mysql -uroot -pxxx
这样,可以吗?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
1.root用户登录OS:
1 row in set (0.00 sec)
mysql> exit
Bye
[root@mysql3 ~]# mysql
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 20
Server version: 5.6.41-log MySQL Community Server (GPL)
Copyright (c) 2000, 2018, 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.
1 row in set (0.00 sec)
mysql> exit
Bye
2.sam用户登录OS:
[sam@mysql3 ~]$ mysql
ERROR 1045 (28000): Access denied for user 'sam'@'localhost' (using password: YES)
[sam@mysql3 ~]$ mysql -uroot -psam123
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 22
Server version: 5.6.41-log MySQL Community Server (GPL)
Copyright (c) 2000, 2018, 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.
1 row in set (0.00 sec)
你要的是这个?
@Yujiaao