ブログ - Raspbian 9.4上にMySQL(marinadb)をインストールしてみた その3 ERROR 1698 (28000): Access denied
Raspbian 9.4上にMySQL(marinadb)をインストールしてみた その3 ERROR 1698 (28000): Access denied
- カテゴリ :
- PC » Raspberry Pi
- ブロガー :
- ujpblog 2018/9/2 18:26
MySQL(marinadb)にデフォルトの管理者ユーザ,rootにパスワードを設定して,Rasbianに標準で付いている一般ユーザpiでMySQLに接続しようとすると,ERROR 1698 (28000): Access deniedとエラーがでる.
原因はUNIX_SOCKET Authentication Pluginなのだけれど,これを簡単に学んでみる.
まずはエラーの状況を再確認するところから.
OSユーザをrootにスイッチするとアクセスできる.
この原因は,UNIX_SOCKET Authentication Pluginが有効化されているからなのだそうです.
Marnadb 5.2から実装されたこの機能は,Unixソケット経由でMarinaDBへ接続する際に,ユーザがOSの資格情報を利用できる.
プラグインが設定されているか確認.
unix_socketとなっているから,そうなのでしょう.
piユーザを作る
Rasbpianには,現在OSインストールしただけの状態なので,OSアカウントは追加していない.よってrootユーザとpiユーザ程度.なので,piユーザをMySQL(marinaDB)上に作成し,プラグイン状態を確認する.
パスワードを設定したから,プラグインは有効では無い模様.
OSのpiユーザから,MySQLのpiユーザを使って接続してみる.
接続できました.
piユーザを作る(unix_socket対応)
MySQL上でcreate userしたアカウントはデフォルトではパスワード認証となっている,,,というかこれまで通りだとパスワードを設定するわけなので,これをunix_socketベースの認証方法を採用してみる.つまり,OSにpiでログインして入れば,MySQLに接続するときにパスワードが不要ということ.
まずは,rootユーザでmysqlに接続.
先ほどMySQL上に作成した,piユーザを削除して,消えたことを確認.
消えました.次に,unix_socketを使って接続できるpiユーザをMySQLに作成.
作成したpiユーザのプラグインを確認.
unix_socketが設定されていることが確認できました.逆にパスワードは設定されていません.
MySQLモニタを抜けて,OSユーザのpiに戻って,MySQLに接続.
piユーザで接続.
無事に接続できました.
OSユーザが存在しないMySQLユーザを作成する
タイトル通りですが,OSアカウントが存在しないpi2というユーザで,MySQLユーザを作成します.
アカウントが作成されました.piユーザで,pi2ユーザを使って接続して確認します.
パスワードなしで接続できません.次に,パスワードを指定します.
接続できました.
参考資料はこちら
Authentication Plugin - Unix Socket
https://mariadb.com/kb/en/library/authentication-plugin-unix-socket/
原因はUNIX_SOCKET Authentication Pluginなのだけれど,これを簡単に学んでみる.
まずはエラーの状況を再確認するところから.
pi@raspberrypi:~ $ mysql -uroot -p🆑
Enter password:🆑
ERROR 1698 (28000): Access denied for user 'root'@'localhost'🈁
pi@raspberrypi:~ $
pi@raspberrypi:~ $ su root🆑
パスワード:
root@raspberrypi:/home/pi# mysql -uroot -p🆑
Enter password:🆑
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 22
Server version: 10.1.35-MariaDB-1 Raspbian testing-staging
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]>
Marnadb 5.2から実装されたこの機能は,Unixソケット経由でMarinaDBへ接続する際に,ユーザがOSの資格情報を利用できる.
プラグインが設定されているか確認.
MariaDB [(none)]> select user,plugin from mysql.user;🆑
+------+-------------+
| user | plugin |
+------+-------------+
| root | unix_socket |🈁
+------+-------------+
1 row in set (0.00 sec)
MariaDB [(none)]>
piユーザを作る
Rasbpianには,現在OSインストールしただけの状態なので,OSアカウントは追加していない.よってrootユーザとpiユーザ程度.なので,piユーザをMySQL(marinaDB)上に作成し,プラグイン状態を確認する.
MariaDB [(none)]> create user 'pi'@'localhost' identified by 'password';🆑
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> select user,plugin from mysql.user;🆑
+------+-------------+
| user | plugin |
+------+-------------+
| root | unix_socket |
| pi | |
+------+-------------+
2 rows in set (0.00 sec)
MariaDB [(none)]>
OSのpiユーザから,MySQLのpiユーザを使って接続してみる.
pi@raspberrypi:~ $ whoami🆑
pi🈁
pi@raspberrypi:~ $ mysql -upi -p🆑
Enter password:🆑
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 25
Server version: 10.1.35-MariaDB-1 Raspbian testing-staging
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]>
piユーザを作る(unix_socket対応)
MySQL上でcreate userしたアカウントはデフォルトではパスワード認証となっている,,,というかこれまで通りだとパスワードを設定するわけなので,これをunix_socketベースの認証方法を採用してみる.つまり,OSにpiでログインして入れば,MySQLに接続するときにパスワードが不要ということ.
まずは,rootユーザでmysqlに接続.
root@raspberrypi:/home/pi# mysql -uroot -p🆑
Enter password:🆑
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 27
Server version: 10.1.35-MariaDB-1 Raspbian testing-staging
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]>
MariaDB [(none)]> drop user 'pi'@'localhost';🆑
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> select user,plugin from mysql.user;🆑
+------+-------------+
| user | plugin |
+------+-------------+
| root | unix_socket |
+------+-------------+
1 row in set (0.01 sec)
MariaDB [(none)]>
MariaDB [(none)]> create user 'pi'@'localhost' identified via unix_socket;🆑
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]>
MariaDB [(none)]> select user,plugin,password from mysql.user;🆑
+------+-------------+-------------------------------------------+
| user | plugin | password |
+------+-------------+-------------------------------------------+
| root | unix_socket | *B6099A7816C8E7B52656686616BA33464BF9AC3B |
| pi | unix_socket | |
+------+-------------+-------------------------------------------+
2 rows in set (0.00 sec)
MariaDB [(none)]>
MySQLモニタを抜けて,OSユーザのpiに戻って,MySQLに接続.
MariaDB [(none)]> quit🆑
Bye
root@raspberrypi:/home/pi# exit🆑
exit
pi@raspberrypi:~ $ whoami🆑
pi🈁
pi@raspberrypi:~ $
pi@raspberrypi:~ $ mysql -upi🆑
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 28
Server version: 10.1.35-MariaDB-1 Raspbian testing-staging
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> quit🆑
Bye🈁
pi@raspberrypi:~ $
OSユーザが存在しないMySQLユーザを作成する
タイトル通りですが,OSアカウントが存在しないpi2というユーザで,MySQLユーザを作成します.
root@raspberrypi:/home/pi# mysql -uroot -p🆑
Enter password:🆑
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 30
Server version: 10.1.35-MariaDB-1 Raspbian testing-staging
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> create user 'pi2'@'localhost' identified by "password";🆑
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> select user,plugin,password from mysql.user;🆑
+------+-------------+-------------------------------------------+
| user | plugin | password |
+------+-------------+-------------------------------------------+
| root | unix_socket | *B6099A7816C8E7B52656686616BA33464BF9AC3B |
| pi | unix_socket | |
| pi2 | | *B6099A7816C8E7B52656686616BA33464BF9AC3B |🈁
+------+-------------+-------------------------------------------+
3 rows in set (0.00 sec)
MariaDB [(none)]>
MariaDB [(none)]> quit🆑
Bye
root@raspberrypi:/home/pi# exit🆑
exit
pi@raspberrypi:~ $ whoami🆑
pi🈁
pi@raspberrypi:~ $ mysql -upi2🆑
ERROR 1045 (28000): Access denied for user 'pi2'@'localhost' (using password: NO)
pi@raspberrypi:~ $
pi@raspberrypi:~ $ mysql -upi2 -p🆑
Enter password:🆑
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 31
Server version: 10.1.35-MariaDB-1 Raspbian testing-staging
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> quit🆑
Bye
pi@raspberrypi:~ $
参考資料はこちら
Authentication Plugin - Unix Socket
https://mariadb.com/kb/en/library/authentication-plugin-unix-socket/