- 追加された行はこの色です。
- 削除された行はこの色です。
#author("2020-07-12T00:24:49+09:00","","")
#navi(../)
* rootでログインできない場合の対処 [#a4aedca5]
本資料では、MariaDBをインストールし mysql_secure_installation コマンドで rootのパスワードを設定したあと、以下のコマンドを実行したらログインできなかった場合の対処です。
$ mysql -u root -h localhost -p
Enter password:
ERROR 1698 (28000): Access denied for user 'root'@'localhost'
#contents
#htmlinsert(db-top.html)
* 動作確認環境 [#b8745f93]
- Ubutnu 20.04 (Ubuntu MATE 利用)
- MariaDB
MariaDB [(none)]> select version();
+--------------------------+
| version() |
+--------------------------+
| 10.3.22-MariaDB-1ubuntu1 |
+--------------------------+
* インストール直後の動作確認 [#x6a0df71]
aptコマンドで以下のようにMariaDBをインストールし、mysql_secure_installationでrootパスワードを設定した状態です。~
sudoを使えばログインできますが、sudoなしの場合は Access denied となってしまいました。
$ mysql -u root
ERROR 1698 (28000): Access denied for user 'root'@'localhost'
$ sudo mysql -u root
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 56
Server version: 10.3.22-MariaDB-1ubuntu1 Ubuntu 20.04
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)]>
* sudoなしで mysql -u root -p が動作するようにする [#ab8a60da]
以下の手順でsudoなしで接続できることを確認しました。
+ MariaDBに接続
sudo mysql -u root
+ 接続されたら、以下のSQLを実行します。~
パスワード部分 sakura を皆さんの環境に合わせて変更してください。
grant all privileges on *.* to root@localhost identified by 'sakura' with grant option;
flush privileges;
exit
sudoなしで再度MariaDBに接続します。
$ mysql -u root -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 77
Server version: 10.3.22-MariaDB-1ubuntu1 Ubuntu 20.04
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)]>
上記の通り、sudoなしで接続できました。