[Osaka/Yokohama] Looking for infrastructure/server side engineers!

[Osaka/Yokohama] Looking for infrastructure/server side engineers!

[Deployed by over 500 companies] AWS construction, operation, maintenance, and monitoring services

[Deployed by over 500 companies] AWS construction, operation, maintenance, and monitoring services

[Successor to CentOS] AlmaLinux OS server construction/migration service

[Successor to CentOS] AlmaLinux OS server construction/migration service

[For WordPress only] Cloud server “Web Speed”

[For WordPress only] Cloud server “Web Speed”

[Cheap] Website security automatic diagnosis “Quick Scanner”

[Cheap] Website security automatic diagnosis “Quick Scanner”

[Reservation system development] EDISONE customization development service

[Reservation system development] EDISONE customization development service

[Registration of 100 URLs is 0 yen] Website monitoring service “Appmill”

[Registration of 100 URLs is 0 yen] Website monitoring service “Appmill”

[Compatible with over 200 countries] Global eSIM “Beyond SIM”

[Compatible with over 200 countries] Global eSIM “Beyond SIM”

[If you are traveling, business trip, or stationed in China] Chinese SIM service “Choco SIM”

[If you are traveling, business trip, or stationed in China] Chinese SIM service “Choco SIM”

[Global exclusive service] Beyond's MSP in North America and China

[Global exclusive service] Beyond's MSP in North America and China

[YouTube] Beyond official channel “Biyomaru Channel”

[YouTube] Beyond official channel “Biyomaru Channel”

スクリプトでmysqlコマンドを実行すると「Warning: Using a password on the command line interface can be insecure」と表示される

インフラエンジニアの伊藤です。
弊社では、スクリプトを使って毎日夜間にデータベースのバックアップを行っています。

よく使うMySQLのバージョンは5.5が多いのですが、5.6を使う機会がありまして、その際にいつもどおりスクリプトを設置して実行してみると、こんなログが出たわけです。

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

※MySQLのバージョンアップ情報についてはコチラ

今までと同じスクリプトを使っているのに見慣れないWarningが出力されてました。

出るだけならまだしも、cronさんがメールしてくるんですよね。。。

パスワードがコマンドラインインターフェイスで見えていることはセキュアじゃないよ

出力されているWarningメッセージは簡単に言うとこんな意味になります。
スクリプトで出力される以外に、コマンドでパスワード直打ちした場合も出力されます。

下記はmysqlコマンドで-pオプションで引数にパスワードを付けてログインした場合です。
2行目に出力されていることがわかると思います。

# mysql -uroot -ppassword
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 3548981
Server version: 5.6.30-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>

[-p]だけにして、別でパスワードを打つ場合は出力されません。
直に書いていることがセキュアじゃない!!というWarningですので。

パスワードの部分をconfファイルに書き出す

このWarningが出ないようにする対処法は、外部ファイルから読み出すという方法です。

外部から読み出すファイルを作成します。

# vim dbaccess.cnf
[client]
user = hoge
password = hogehoge
host = 192.168.1.1

パスワードが書かれたファイルなので、アクセス権は最小限に
# chmod 400 dbaccess.cnf

mysqlコマンドやmysqldumpコマンドにおいて、このファイルを読みだすようにしてあげればOKです。

# mysql --defaults-extra-file=dbaccess.cnf
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 72755232
Server version: 5.6.30-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>

無事接続が出来ますので、これをスクリプトに組み込んであげればOKですね。

MySQLについては他の記事も書いてますので、コチラも併せてご覧ください。

mysqlのデータを別ディレクトリに保存する

この記事がお役に立てば【 いいね 】のご協力をお願いいたします!
7
読み込み中...
7 票, 平均: 1.00 / 17
66,752
X facebook はてなブックマーク pocket
[2024.6.30 CentOS support ended] CentOS server migration solution

[2024.6.30 CentOS support ended] CentOS server migration solution

[2025.6.30 Amazon Linux 2 support ended] Amazon Linux server migration solution

[2025.6.30 Amazon Linux 2 support ended] Amazon Linux server migration solution

[Osaka/Yokohama] Actively recruiting infrastructure engineers and server side engineers!

[Osaka/Yokohama] Actively recruiting infrastructure engineers and server side engineers!

The person who wrote this article

About the author