Passwords 以编程方式更改过期的Oracle DB密码?
在我工作的地方,一些数据库会从生产环境复制到测试环境,但是DBA会在复制之后将(新的)测试数据库上的所有密码设置为过期,这样生产密码就不知道了。因此,如果我运行sqlplus并使用特定用户名连接到测试数据库,它会立即提示我输入新密码 有没有办法通过java应用程序或shell脚本自动更改特定用户过期的oracle 10g数据库密码?在Unix上 如果您使用的是unix,则可以使用shell脚本 我已经这样测试过了:Passwords 以编程方式更改过期的Oracle DB密码?,passwords,oracle10g,Passwords,Oracle10g,在我工作的地方,一些数据库会从生产环境复制到测试环境,但是DBA会在复制之后将(新的)测试数据库上的所有密码设置为过期,这样生产密码就不知道了。因此,如果我运行sqlplus并使用特定用户名连接到测试数据库,它会立即提示我输入新密码 有没有办法通过java应用程序或shell脚本自动更改特定用户过期的oracle 10g数据库密码?在Unix上 如果您使用的是unix,则可以使用shell脚本 我已经这样测试过了: drop user foo cascade; create user foo i
drop user foo cascade;
create user foo identified by old_password password expire;
grant create session to foo;
exit
现在使用这个小脚本:
cat <<DOG | sqlplus foo/old_password
new_password
new_password
exit
DOG
然后,更改密码并将其连接到实例:
sqlplus foo/new_password@ORCL
显然,您应该将cat…
构造放在适合您的shell脚本中
在窗户上
在Windows上,您可以使用这样的批处理文件
@(
echo new_password
echo new_password
) | sqlplus foo/old_password@ORCL
我假设您遇到的问题是
ORA-28001:密码已过期
。这通常是由于ALTER USER unittest PASSWORD EXPIRE
或由于用户的配置文件设置而导致密码过期的结果。这是相当棘手的情况
当您连接到SQL*Plus
时,它会提示您输入新密码,然后设置新密码如下:
jxa@ub16a|2014$ sqlplus unittest/unittest@//localhost/orclpdb1
SQL*Plus: Release 12.1.0.2.0 Production on Fri Dec 22 13:06:04 2017
Copyright (c) 1982, 2014, Oracle. All rights reserved.
ERROR:
ORA-28001: the password has expired
Changing password for unittest
New password:
Retype new password:
Password changed
Connected to:
Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options
UNITTEST@ORCLCDB>
但对于JDBC或cx_Oracle,此异常会导致连接死机,并且您无法使用它来发布由yy REPLACE zz标识的ALTER USER xx
因此,您需要做的是删除现有的连接,并使用神奇的设置再次重新连接。JDBC的神奇之处在于将连接属性设置为新密码。只需在谷歌上搜索OCINewPassword
,就可以找到示例
使用Python的cx_-Oracle.connect
和cx_-Oracle.Connection
具有newpassword=
参数,该参数允许在报告当前密码过期时以编程方式更改密码
在这两种情况下,使用旧密码连接并设置OCINewPassword
(JDBC)或newpassword
(Python)就足够了。结果是连接正常,用户的密码更改为新密码
通过这种方式,它为过期的oracle用户打开了自动更改密码的途径。shell脚本:那就在unix上了?实际上,这是在RedHat Linux系统上。此外,我在让脚本实际更改密码方面遇到了困难。我一直收到一个“密码不匹配”错误。但是,我会继续调整它,并在我让它工作时发布脚本的源代码。
jxa@ub16a|2014$ sqlplus unittest/unittest@//localhost/orclpdb1
SQL*Plus: Release 12.1.0.2.0 Production on Fri Dec 22 13:06:04 2017
Copyright (c) 1982, 2014, Oracle. All rights reserved.
ERROR:
ORA-28001: the password has expired
Changing password for unittest
New password:
Retype new password:
Password changed
Connected to:
Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options
UNITTEST@ORCLCDB>