MySQL之实现免密登录(设置默认登录用户及密码)

11 篇文章 0 订阅
10 篇文章 0 订阅

前言

  • MySQL版本:5.7.10
  • 本文介绍的免密登录方式的原理就是在配置文件中设置mysql客户端命令行工具的默认参数,实现登录时可以直接使用设置参数进行登录,相当于设置了默认登录用户,并且只在修改了配置文件的主机上使用MySQL客户端登录时才有效

查看配置配置文件生效顺序

使用mysql --help命令可以输出mysql命令行工具的使用帮助手册,其中Default options are read from the following files in the given order:字样的后续输出即为配置文件的读取和生效顺序,后者文件中的参数设置会覆盖前者

Liunx上可以使用以下命令查看:

mysql --help | tail -n +$(mysql --help | grep -n 'given order' | cut -d ':' -f 1) | head -n2
[tomandersen@localhost ~]$ mysql --help | tail -n +$(mysql --help | grep -n 'given order' | cut -d ':' -f 1) | head -n2
Default options are read from the following files in the given order:
/etc/my.cnf /etc/mysql/my.cnf /usr/local/mysql/etc/my.cnf /usr/local/mysql/my.cnf ~/.my.cnf

在配置文件中设置相应工具的默认参数

以~/.my.cnf配置文件为例,设置mysql、mysqldump工具的默认参数:

[mysql]
user=root
password=root

[mysqldump]
user=root
password=root

于是在使用mysql客户端、mysqldump工具时能够使用默认用户免密登录:

[tomandersen@localhost ~]$ mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 82
Server version: 5.7.17-log MySQL Community Server (GPL)

Copyright (c) 2000, 2016, 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>

End~

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值