mysql5.6命令行不能使用密码的安全措施

配置了--login-path后,尝试

shell>mysql --login-path  死活要报错说:未知的参数;

原来,之前有人在.bashrc做过命令别名

alias mysql='mysql -h$host -uroot -p$password -A'

而使用--login-path方式的时候,该参数必须为第一个参数位置;

为了保留mysql的别名,又想用--login-path的方式方便配置定时备份任务,

可以这样登录:

shell># /usr/local/mysql/bin/mysql --login-path=$name

============================

http://dev.mysql.com/doc/refman/5.6/en/option-files.html

On Unix, Linux and OS X, MySQL programs read startup options from the following files, in the specified order (top items are used first).

File NamePurpose
/etc/my.cnf Global options
/etc/mysql/my.cnf Global options
SYSCONFDIR/my.cnf Global options
$MYSQL_HOME/my.cnf Server-specific options
defaults-extra-file The file specified with --defaults-extra-file=path, if any
~/.my.cnf User-specific options
~/.mylogin.cnf Login path options

~ represents the current user's home directory (the value of $HOME).

==================================

http://it.i88.ca/2014/10/how-to-fix-mysql-warning-using-password.html

How to fix MySQL Warning: Using a password on the command line interface can be insecure

 
The mysql_config_editor utility (available as of MySQL 5.6.6) enables you to store authentication credentials in an encrypted login file named .mylogin.cnf. The file location is the %APPDATA%\MySQL directory on Windows and the current user's home directory on non-Windows systems. The file can be read later by MySQL client programs to obtain authentication credentials for connecting to MySQL Server.

mysql_config_editor set --login-path=local --host=localhost --user=username --password

Then you can use in your shell script:

mysql --login-path=local 

instead of:

mysql -u username -p pass 

You need to put --login-path as the first parameter, or else you will get something similar to
"unknown variable 'login-path=local'"


SET

shell> mysql_config_editor set --login-path=local
         --host=localhost --user=localuser --password
Enter password: enter password "localpass" here
shell> mysql_config_editor set --login-path=remote
         --host=remote.example.com --user=remoteuser --password
Enter password: enter password "remotepass" here

SHOW

shell> mysql_config_editor print --all
[local]
user = localuser
password = *****
host = localhost
[remote]
user = remoteuser
password = *****
host = remote.example.com

USE

For example, to connect to the local server, use this command:
shell> mysql --login-path=local
To connect to the remote server, use this command:
shell> mysql --login-path=remote
 

 

======================================================

MySQL5.6 Using a password on the command line interface can be insecure

http://stackoverflow.com/questions/20751352/suppress-warning-messages-using-mysql-from-within-terminal-but-password-written

If your MySQL client/server version is a 5.6.x a way to avoid the WARNING message are using themysql_config_editor tools:

mysql_config_editor set --login-path=local --host=localhost --user=username --password

Then you can use in your shell script:

mysql --login-path=local -e "statement"

instead of:

mysql -u username -p pass -e "statement"

shareimprove this answer
shell> mysql_config_editor set --login-path=local
     --host=localhost --user=localuser --password
Enter password: enter password "localpass" here
shell> mysql_config_editor set --login-path=remote
     --host=remote.example.com --user=remoteuser --password
Enter password: enter password "remotepass" here

To see what mysql_config_editor wrote to the .mylogin.cnf file, use the print command:

shell> mysql_config_editor print --all
[local]
user = localuser
password = *****
host = localhost
[remote]
user = remoteuser
password = *****
host = remote.example.com

The print command displays each login path as a set of lines beginning with a group header indicating the login path name in square brackets, followed by the option values for the login path. Password values are masked and do not appear as clear text.

As shown by the preceding examples, the .mylogin.cnf file can contain multiple login paths. In this way, mysql_config_editor makes it easy to set up multiple “personalities” for connecting to different MySQL servers. Any of these can be selected by name later using the --login-path option when you invoke a client program. For example, to connect to the local server, use this command:

shell> mysql --login-path=local

To connect to the remote server, use this command:

shell> mysql --login-path=remote

 

http://bbs.cqsztech.com/dv_rss.asp?s=xhtml&boardid=3&id=2241&page=4

每次都要输入mysql -u root -p -h localhost 是不是很麻烦呢。还要输入密码。
mysql 提供了一种方法叫做登录路径。
shell> mysql_config_editor set --login-path=remote
--host=remote.example.com --user=remoteuser --password

使用这个方法会在当前的用户目录下产生一个加密文件:.mylogin.
下次登录的时候可以 直接输入mysql 登录。或者使用mysql --load-path=remote

查看当前那些用户使用了 登录路径
shell> mysql_config_editor print --all
[local]
user = localuser
password = *****
host = localhost
[remote]
user = remoteuser
password = *****
host = remote.example.com


清除登录路径 
shell>mysql_config_editor reset 

 

http://zhuxiaoyuan.net/?p=82

在MySQL5.6.6之前,客户端登陆MySQL,指定用户名、密码有以下方式:
1.在命令行中通过指定选项,显示指定用户名/密码;
2.在配置文件中,明文指定用户名/密码信息;
以上形式有个明显的缺点就是用户/密码信息暴露,存在安全隐患,很容易被不法分子利用;

到MySQL5.6引入了mysql_config_editor命令,将用户/密码等登陆信息加密方式存放在.mylogin.cnf文件中(Linu存放在当前用户HOME目录下),提供了MySQL系统的安全性;

命令如下:

1
mysql_config_editor [program_options] command [command_options]

program_options:是mysql_config_editor选项;
command:是指示需要执行的命令;
command_options:command命令对应的选项;

command指定在.mylogin.cnf文件上执行什么动作;set:添加login path到.mylogin.cnf文件,remove从.mylogin.cnf文件中删除login path,print显示loginpath内容;

新增一个login path:

1
mysql_config_editor set --login-path=zxylogininfo --user=zxy --password

会出现交互界面提示输入密码,这样登陆信息以加密的形式存放到.mylogin.cnf文件中、

查看刚才登陆信息:

1
mysql_config_editor print --all

显示信息:
[zxylogininfo]
user = zxy
password = *****

客户端使用–login-path登陆MySQL服务器:

1
mysql --login-path=zxylogininfo --socket=/home/mysql_data/run/mysqld.sock3305

登陆输出信息:
~]# mysql –login-path=zxylogininfo –socket=/home/mysql_data/run/mysqld.sock3305
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1032
Server version: 5.6.19-log MySQL Community Server (GPL)

Copyright (c) 2000, 2014, 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服务器:

1
mysql -uzxy -pzxy --socket=/home/mysql_data/run/mysqld.sock3305

登陆输出信息:
~]# mysql -uzxy -pzxy –socket=/home/mysql_data/run/mysqld.sock3305
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1039
Server version: 5.6.19-log MySQL Community Server (GPL)

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

注意:
1.优先级问题,命令行中指定的选项的优先级高于.mylogin.cnf指定的选项,.mylogin.cnf指定的选项高于其他配置文件中的选项;

 

http://www.cnblogs.com/rockbes/p/3972763.html

mysql_config_editor出现在mysql5.6.6以后的版本,可以给指定的连接和密码生成一个加密文件.mylogin.cnf,默认位于当前用户家目录下。通过该文件可以使用mysql、mysqladmin等直接登录,避免明文密码出现在脚本中。
notice:使用该特性要求当前主机的mysql版本在5.6.6版本及以上,对将要登陆的mysql服务器版本没有要求。
Usage:
生成加密文件
[root@master ~]# mysql_config_editor set --login-path=jjscj --host=192.168.1.190 --user=jjscj --password 
Enter password:
[root@master ~]# ll ~/.mylogin.cnf 
-rw------- 1 root root 248 Aug 28 14:58 /root/.mylogin.cnf
使用加密文件登录:
[root@master ~]# mysql --login-path=jjscj 
Welcome to the MySQL monitor.
查看当前主机上的加密文件:
[root@master ~]# mysql_config_editor print --all 
[local] 
user = root 
password = ***** 
host = localhost 
[jjscj] 
user = jjscj 
password = ***** 
host = 192.168.1.190
[remote]
user = jjscj
password = *****
host = 192.168.1.190
删除某个加密登陆:
[root@master ~]# mysql_config_editor remove --login-path=remote 
[root@master ~]# mysql_config_editor print --all 

[local] 
user = root 
password = ***** 
host = localhost 
[jjscj] 
user = jjscj 
password = ***** 
host = 192.168.1.190
重置所有
[root@master ~]# mysql_config_editor reset 
 
http://blog.csdn.net/lwei_998/article/details/41692649

从Mysql5.6.6 开始mysql_config_editor允许存储加密的身份验证文件.mylogin.cnf

.mylogin.cnf在系统中的位置
Windows :%APPDATA%\MySQL 
Linux:$HOME/.mylogin.cnf

1.用mysql_config_editor生成.mylogin.cnf
$mysql_config_editor set --login-path=3336 -S /mysqlweb/mysql3336/logs/mysql.sock  --user=root --password 
Enter password:

$mysql_config_editor set --login-path=3326 --host=127.0.0.1 -P3326 --user=root --password
Enter password:


$ls  ~/.mylogin.cnf    
/home/mysql/.mylogin.cnf

2.查看.mylogin.cnf的内容
$mysql_config_editor print --all
[3336]
user = root
password = *****
socket = /mysqlweb/mysql3336/logs/mysql.sock
[3326]
user = root
password = *****
host = 127.0.0.1
port = 3326
在.mylogin.cnf中密码是经过加密的。

3.使用mysql_config_editor中设置的login-path登录mysql
$mysql --login-path=3326 -e"show variables like'port'\G"
*************************** 1. row ***************************
Variable_name: port
        Value: 3326
        
$mysql --login-path=3336 -e"show variables like'port'\G" 
*************************** 1. row ***************************
Variable_name: port
        Value: 3336          
        
参考文档:
http://dev.mysql.com/doc/refman/5.6/en/mysql-config-editor.html       

 

http://blog.csdn.net/seteor/article/details/18084149

mysql_config_editor是于用户安全认证的一个工具,使用方式如下:

mysql_config_editor set --login-path=test --user=root --host=localhost --password

Enter password: (输入密码)

登录测试:
mysql --login-path=test

登录成功。

它生成的加密文件会存放在用户主目录下

[root@localhost ~]# file ~/.mylogin.cnf 
.mylogin.cnf: data



修改用户密码后再测试登录
mysql>set password for root@'localhost'=password('abc');
mysql>flush privileges;
登录测试:
mysql --login-path=test
登录失败。


结论:用户密码被修改后,需要重新创建login-path。

 

http://www.wo81.com/tec/db/mysql/2014-05-12/212.html

将网站迁移到了阿里云服务器,做数据库恢复时,发现多了一个提示:

# mysql -uroot -p密码 mydb</mydb.sql
Warning: Using a password on the command line interface can be insecure.
警告:在命令行上使用密码是不安全的。
 
为什么以前没有提示呢?登录以前服务器
# mysql -uroot -p
Enter password: 输入密码
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4857
Server version: 5.5.31 MySQL Community Server (GPL) by Remi
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> 
 
版本是5.5.31,恢复测试:
mysql -uroot -p密码 mydb</mydb.sql
没有任何提示。
 
看看阿里云服务器上的mysql版本:
# /alidata/server/mysql/bin/mysql -uroot -p
Enter password: 输入密码
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3593
Server version: 5.6.15-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> 
版本是:5.6.15。
看来mysql5.6不建议在命令行中包含密码,那该怎么办呢?
网上看到一些资料,发现都是针对mysqldump的,于是做了个尝试,修改my.cnf(阿里云安装脚本安装的mysql:/etc/my.cnf,一般情况:/etc/mysql/my.cnf)文件的 [mysql] 部分,增加了用户和密码行,如下所示:
[mysql]
……(省略)
user=root
password=root用户的密码
 
然后做数据库恢复测试:
# mysql -uroot mydb</mydb.sql
的确没有提示了,而且也恢复成功了。
 
经过实验,mysql 5.6 数据库备份(mysqldump)时,也有Warning: Using a password on the command line interface can be insecure. 的警告信息,避免提示的做法是修改my.cnf(阿里云安装脚本安装的mysql:/etc/my.cnf,一般情况:/etc/mysql/my.cnf)文件的 [mysqldump] 部分,如下所示:
[mysqldump]
……(省略)
user=root
password=root用户的密码
可是,为了避免一个警告,将密码存储在my.cnf文件中,这样执行mysqldump或者mysql都不需要密码了,这本身就不安全!!!
可要是不保存在这个文件中,使用包含密码命令执行,别人也可能通过history命令或者~/.bash_history文件中找到密码。怎么办呢?
我个人认为这只是一个提示,不影响使用,所以,忽略它吧!!!
我们要做的就是:连接服务器使用ssh2协议(加密),继续用命令行的方式,修改~/.bash_logout文件,增加history -c,使得用户退出时自动清理命令历史记录就可以了。
建议做法:修改~/.bash_logout文件,增加两条命令:history -c和>~/.bash_history。 
对于阿里云的用户来说,也可以在~/.bash_logout文件中增加如下命令清理mysql的一些日志:
>.mysql_history
郁闷的是:如上的 history -c 和 >~/.bash_history 有时生效有事不生效!!!
 
 
http://niweiwei.iteye.com/blog/2153065

mysql版本为:5.6.19,Mysql5.6版本对安全性进行了增强

在使用mysql的导出命令进行数据库备份时,出现:

Warning: Using a password on the command line interface can be insecure;

是因为在导出命令中使用了-ppassword所导致的,解决方法是:

1、使用my.cnf来存储密码,格式如下:

[mysqldump]

user=root

 

password=root

2、在mysqldump命令行使用 --defaults-file属性来指定my.cnf的位置

mysqldump --defaults-file=".mylogin.cnf" -hlocalhost -P3306 --user=root --routines --default-character-set=utf8 --max_allowed_packet=1G testdb> testdb.sql

 

 

 

 

 

posted @ 2015-01-28 17:56  陳聽溪  阅读(1758)  评论(0)    收藏  举报