コピペコードで快適生活

明日使えるソースを自分のために

ERROR 2049 (HY000): Connection using old (pre-4.1.1) authentication protocol refused (client option 'secure_auth' enabled)

$ mysql -u app_user -h 192.168.0.1 -p
Enter password:
ERROR 2049 (HY000): Connection using old (pre-4.1.1) authentication protocol refused (client option 'secure_auth' enabled)

とでた。 mysql_native_passwordで認証しようとしたけど、mysql_old_passwordでパスワード管理されているユーザなのでログインできないよ、ということらしい。

オプションつけて接続する

MySQLの5.7.5以降のバージョンでは非推奨

# 普通に接続するとだめなので
$ mysql -u app_user -h 192.168.0.1 -p
Enter password:
ERROR 2049 (HY000): Connection using old (pre-4.1.1) authentication protocol refused 
(client option 'secure_auth' enabled)

# --skip-secure-authオプションつける
$ mysql -u app_user -h 192.168.0.1 -p --skip-secure-auth
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.

デフォルトでオプションを有効にする

MySQLの5.7.5以降のバージョンでは非推奨

mysql --help
# 略
Default options are read from the following files in the given order:
/etc/my.cnf /etc/mysql/my.cnf /usr/etc/my.cnf ~/.my.cnf
# 略

なので、/etc/my.cnf あたりに

[client]
skip-secure-auth

追加してからmysqlコマンドで接続すればOK。