我想编写一个cron作业,它传递一个shell脚本来登录到MySQL数据库并执行一些查询。要以特定用户的身份连接到数据库,我想知道我必须隐藏或不使用密码的选项?
我正在寻找的答案是使用信任用户在PostgreSQL中进行信任身份验证,这样就不需要密码了。
我知道您可以在服务器中创建一个密码配置文件,但是由于密码经常更改,我想要一些更动态的内容。
我有什么选择?
发布于 2014-03-07 16:24:49
简单的任务去做!!在这个链接中,您将找到一篇如何撰写文章,向您展示这是如何完成的。
我将在这里描述它!-chose用户无需密码登录什么,并在您的主目录中创建一个名为.my.cnf的文件,并将其权限更改为chmod 600。-它应该做这个工作-我使用这个与我的管理用户。
[mysqldump]
user = --user used to run backup
password = --password of the user
[mysql]
user= --user used to run backup
password= --password of the user这是如何工作的例子:
[root@BIH001 ~]# cat /root/.my.cnf
[mysqldump]
user = root
password = ***********
[mysql]
user= adrian
password= ***********下一步我切换到这个用户(禤浩焯a SO级) :
[root@BIH001 ~]# su - adrian并连接到mysql,不需要密码或任何用户:
(当然,你必须在数据库中有这个帐户,而他也只会看到你给他看的东西。)
[adrian@BIH001 ~]$ mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 962888
Server version: 5.1.69-log Source distribution
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>修改.my.cnf文件并添加没有密码的根用户连接:
[root@BIH001 ~]# cat /root/.my.cnf
[mysqldump]
user = root
password = ***********
[mysql]
user= root
password= ***********
[root@BIH001 ~]# mysql -uroot
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 963365
Server version: 5.1.69-log Source distribution
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>,我希望这能让你明白!!
https://stackoverflow.com/questions/22255207
复制相似问题