关于Oracle和MySQL中的无密码登录

无密码登录在一定程度上能够简化流程,对于密码敏感,但是又需要提供访问权限的情况下是一个不错的选择。尤其是在乙方在做一些操作的时候,要密码和给密码是一个纠结的问题。不给没法工作,给了又对信息安全又影响。
在Oracle和MySQL中都有相应的解决方案,大道至简,这个功能的目的都是类似的。
在Oracle中可以通过设置wallet来实现,在10g版本开始支持。而在MySQL中自5.6版本开始可以使用--login-path来实现。
先来看看Oracle中的wallet实现无密码登录,可以通过mkstore来配置,我们可以使用--help得到命令使用的帮助。
[ora11g@oel1 admin]$ mkstore --help
Oracle Secret Store Tool : Version 11.2.0.1.0 - Production
Copyright (c) 2004, 2009, Oracle and/or its affiliates. All rights reserved.
No wallet location specified. 
mkstore [-wrl wrl] [-create] [-createSSO] [-createLSSO] [-createALO] [-delete] [-deleteSSO] [-list] [-createEntry alias secret] [-viewEntry alias] [-modifyEntry alias secret] [-deleteEntry alias] [-createCredential connect_string username password] [-listCredential] [-modifyCredential connect_string username password] [-deleteCredential connect_string] [-help] [-nologo]
我们首先来创建钱包,指定钱包路径为/u02/ora11g/wallet,对于密码还是有一定的要求,太简单也不行。
$ mkstore -wrl /u02/ora11g/wallet -create
Oracle Secret Store Tool : Version 11.2.0.1.0 - Production
Copyright (c) 2004, 2009, Oracle and/or its affiliates. All rights reserved.
Enter password:          
Enter password again:   
生成钱包后,会在指定的路径下生成两个文件。
$ ll
total 8
-rw------- 1 ora11g dba 3589 May 17 21:37 cwallet.sso
-rw------- 1 ora11g dba 3512 May 17 21:37 ewallet.p12
我们可以指定临时的连接串来配置到钱包里面,比如我们认为test11g是一个临时连接串,可以使用tnsping来测试,确保连接串是可访问的。
$tnsping test11g
Attempting to contact (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = oel1.oracle.com)(PORT = 1511))) (CONNECT_DATA = (SERVICE_NAME = TEST11G)))
OK (0 msec)
配置完成之后,我们需要在登录之前在sqlnet.ora中配置钱包的路径。sqlnet.ora中需要配置的内容如下:
$ cat sqlnet.ora
WALLET_LOCATION =
  (SOURCE =
    (METHOD = FILE)
    (METHOD_DATA =
      (DIRECTORY = /u02/ora11g/wallet)
    )
  )

SQLNET.WALLET_OVERRIDE=true
这些配置都搞定以后我们就可以指定对应的连接串,对应的用户名密码。
$ mkstore -wrl /u02/ora11g/wallet -createCredential test11g n1 n1
Oracle Secret Store Tool : Version 11.2.0.1.0 - Production
Copyright (c) 2004, 2009, Oracle and/or its affiliates. All rights reserved.
Enter wallet password:  l       1
Create credential oracle.security.client.connect_string1
如果希望查看验证的明细信息,可以使用下面的命令。
[ora11g@oel1 wallet]$ mkstore -wrl /u02/ora11g/wallet -listCredential
Oracle Secret Store Tool : Version 11.2.0.1.0 - Production
Copyright (c) 2004, 2009, Oracle and/or its affiliates. All rights reserved.
Enter wallet password:              
List credential (index: connect_string username)
1: test11g n1

配置完成之后工作就完成了,我们可以简单验证一下。
$ sqlplus /@test11g
SQL*Plus: Release 11.2.0.1.0 Production on Sun May 17 21:45:59 2015
With the Partitioning, OLAP, Data Mining and Real Application Testing options
n1@TEST11G> 

如果需要禁用删除也是很方便的。
删除验证信息
[ora11g@oel1 wallet]$ mkstore -wrl /u02/ora11g/wallet -deleteCredential test11g
Oracle Secret Store Tool : Version 11.2.0.1.0 - Production
Copyright (c) 2004, 2009, Oracle and/or its affiliates. All rights reserved.
Enter wallet password:          1
Delete credential 
Delete 1
删除钱包

[ora11g@oel1 wallet]$  mkstore -wrl /u02/ora11g/wallet -delete
Oracle Secret Store Tool : Version 11.2.0.1.0 - Production
Copyright (c) 2004, 2009, Oracle and/or its affiliates. All rights reserved.
Enter wallet password:          1
也可以选择相应修改sqlnent.ora里面的配置
  
而如果使用MySQL来实现,则需要通过mysql_config_editor来配置。

mysql_config_editor的命令提示如下,可以看出可使用的选项还是相对比较简单的。
[mysql@oel1 ~]$ mysql_config_editor set --help
mysql_config_editor Ver 1.0 Distrib 5.6.23, for linux-glibc2.5 on i686
Copyright (c) 2012, 2015, 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.

MySQL Configuration Utility.
Description: Write a login path to the login file.
Usage: mysql_config_editor [program options] [set [command options]]
  -?, --help          Display this help and exit.
  -h, --host=name     Host name to be entered into the login file.
  -G, --login-path=name 
                      Name of the login path to use in the login file. (Default
                      : client)
  -p, --password      Prompt for password to be entered into the login file.
  -u, --user=name     User name to be entered into the login file.
  -S, --socket=name   Socket path to be entered into login file.
  -P, --port=name     Port number to be entered into login file.
  -w, --warn          Warn and ask for confirmation if set command attempts to
                      overwrite an existing login path (enabled by default).
                      (Defaults to on; use --skip-warn to disable.)
我们直接可以通过一个命令来完成配置,制定这个无密码登录的别名为fastlogin

[mysql@oel1 ~]$ mysql_config_editor set --login-path=fastlogin --user=root --host=localhost --password --socket=/u02/mysql/mysqld_mst.sock
Enter password: 
配置完成之后,会在当前路径下生成一个隐藏文件.mylogin.cnf

[mysql@oel1 ~]$ ll -la .mylogin*
-rw------- 1 mysql dba 480 May 17 22:10 .mylogin.cnf
如果需要查看里面的明细信息,可以使用如下的命令,当然密码是不会显示出来的。
[mysql@oel1 ~]$ mysql_config_editor print --login-path=fastlogin 
[fastlogin]
user = root
password = *****
host = localhost
socket = /u02/mysql/mysqld_mst.sock

大功告成,这个时候直接登录即可。
[mysql@oel1 ~]$ mysql --login-path=fastlogin
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.6.23-enterprise-commercial-advanced-log MySQL Enterprise Server - Advanced Edition (Commercial)
Copyright (c) 2000, 2015, 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_config_editor remove --login-path=fastlogin 

这个时候再次查看就没有任何信息了。
[mysql@oel1 ~]$ mysql_config_editor print --login-path=fastlogin 
但是默认的login文件还是存在的。
[mysql@oel1 ~]$ ls -la
total 1204364
drwxr-xr-x  2 mysql dba       4096 Apr 21 14:58 log
drwxr-xr-x  3 mysql dba       4096 Nov  4  2014 meb-3.11.1-linux-glibc2.5-x86-32bit
-rw-------  1 mysql dba        336 May 22 12:40 .mylogin.cnf

时间: 2024-07-30 23:08:55

关于Oracle和MySQL中的无密码登录的相关文章

oracle转Mysql中,varchar2(10)和number应该转换为什么类型? (转)

一. varchar2(10)和number应该转换为什么类型? oracle转成mysql时:varchar2(10)可以转成varchar(10)number则要看oracle中存储的具体是什么类型的数据:1.如果是整型,那么mysql中,用int即可:2.如果是带小数位的,那么mysql中可用numeric类型. 注:mysql中没有varchar2(10)和number这两个数据类型   二. Mysql varchar VS Oracle varchar2 mysql和oracle做数

通过oracle类比MySQL中的字节字符问题

在几个月前写过一篇博文 MySQL数据类型 http://blog.itpub.net/23718752/viewspace-1371434/  当时写完以后有同事朋友就提出了一些疑问,对于汉字在MySQL和Oracle中的存放情况希望我能够详细的说说.  关于MySQL中的varchar字符类型,自己的操作都是基于字符集UTF-8.  对于存放汉字,涉及到字符,字节,编码的一些知识,我查了一下,自己先补补,发现有一个帖子已经描述的很详细了.直接引用过来.  http://www.regexla

SQL Server、Oracle和MySQL中查出值为NULL的替换

在SQL Server Oracle MySQL当数据库中查出某值为NULL怎么办? 1.MSSQL: ISNULL() 语法 ISNULL ( check_expression , replacement_value ) 参数 check_expression 将被检查是否为 NULL的表达式.check_expression 可以是任何类型的. replacement_value 在 check_expression 为 NULL时将返回的表达式.replacement_value 必须与

Java、JavaScript、Oracle、MySQL中实现的MD5加密算法分享_java

MD5,全称为 Message Digest Algorithm 5(消息摘要算法第五版).详情请参考 维基百科:MD5 MD5加密后是一个字节数组, 但我们一般是取其十六进制的字符串表示法,当然,十六进制数字符串是区分大小写,在 mysql数据库,Java,和JavaScript语言中,一般是使用小写的字符串来表示, 而在 Oracle数据库官方提供的包中,返回的是大写字符串,这算是一个坑,如果你想要执行多次 md5,可能需要转换为小写. 相关的代码如下: 1. Java版MD5 MD5Uti

Oracle和MySQL中短小精悍的SQL

如果让你写一个简单牛叉的SQL,数据库类型不限,你会写出什么样的SQL语句. Oracle    如果是Oracle,我就写个drop table dual; 这个SQL看起来很简单,包含的信息量还是蛮大的,首先对于dual表你得有一定的认识和了解,而这个视图和一般的数据字典不同,如果删除之后,直接会导致数据库不可用.恢复起来需要一个隐含参数来调整.    当然如果想换一个角度来,写出一些含有人生哲理的SQL来,这方面得下不少功夫了.    我想了一个,比如Flashback database

Oracle和MySQL分组查询GROUP BY

Oracle和MySQL分组查询GROUP BY 真题1.Oracle和MySQL中的分组(GROUP BY)有什么区别?答案:Oracle对于GROUP BY是严格的,所有要SELECT出来的字段必须在GROUP BY后边出现,否则会报错:"ORA-00979: not a GROUP BY expression".而MySQL则不同,如果SELECT出来的字段在GROUP BY后面没有出现,那么会随机取出一个值,而这样查询出来的数据不准确,语义也不明确.所以,作者建议在写SQL语句

关于ORACLE和MYSQL中文字符乱码的根源剖析

关于数据库的字符集问题一直都是一个比较恶心的问题,如果不了解其实质可能一直 都搞不清楚这个问题的根源,只能出了问题去度娘,这里我打算兼容ORACLE和MYSQL对字符集 的处理来描述乱码出现的情形和如何防止乱码问题出现的可能,本文只用UTF-8和GBK为 例子进行描述,请大家先记住'去'这个字的UTF8和GBK编码,因为整个文章将用'去'字为 例子进行讲述 GBK     UTF8   中文 C8A5    E58EBB  去 同时整篇文章数据库DATABASE端的字符集始终为UTF8 一般来讲

MySQL中如何实现类似Oracle的序列

Oracle一般使用序列(Sequence)来处理主键字段,而MySQL则提供了自增长(increment)来实现类似的目的: 但在实际使用过程中发现,MySQL的自增长有诸多的弊端:不能控制步长.开始索引.是否循环等:若需要迁移数据库,则对于主键这块,也是个头大的问题. 本文记录了一个模拟Oracle序列的方案,重点是想法,代码其次. Oracle序列的使用,无非是使用.nextval和.currval伪列,基本想法是:1.MySQL中新建表,用于存储序列名称和值:2.创建函数,用于获取序列表

oracle中的clob在mysql中的移植

问题描述 oracle中的clob在mysql中的移植 oracle中的clob一般会在mysql移植成什么数据类型,empty_clob()又会用什么代替呢?跪求 解决方案 数据库移植: 从Oracle移植到MySQL 注意databasePlatformOracle移植到mysql注意事项oracle移植到mysql注意事项 解决方案二: 数据库移植: 从Oracle移植到MySQL 注意databasePlatform Oracle移植到mysql注意事项 oracle移植到mysql注意