msyql本地登录不需要密码的方法

该方法只是linux下使用的,可以实现mysq的免用户和密码登录,不过要注意的是一定要设置好权限不能让他人看到该文件。



1.在需要进行mysq登录操作的用户下建立如下的文件:

vi ~/.my.cnf

将下边的内容放入上方的文件当中

[client]

host='localhost'

#登录的用户名

user='system'

#用户的密码

password='guan'



2.编辑完成的文件如下图:


[root@master2 ~]# cat ~/.my.cnf

[client]

host='localhost'

#登录的用户名

user='system'

#用户的密码

password='guan'




3.测试

保存后,再登录mysql的时候,只需要输入mysql们不需要加后面的用户名和密码


[root@master2 ~]# mysql   #后边没有跟用户名和密码

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 4

Server version: 5.6.14-log MySQL Community Server (GPL)

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>   ##可以看到我们已经登陆成功


注意点:通过下边的操作去除他人查看的权限放置密码泄漏

[root@master2 ~]# chmod 600 ~/.my.cnf

[root@master2 ~]# ll ~/.my.cnf

-rw------- 1 root root 93 May  8 06:23 /root/.my.cnf

你可能感兴趣的:(msyql本地登录不需要密码的方法)