MySQLを使用するためインストールしたが、毎回rootのパスを聞かれるので、パスワード無しでログインできるようにしました。
この作業に当たって、ネットに多く転がっているコマンドでは出来ませんでした。
今回はこの出来なかった所も踏まえて紹介をしていきたいと思います。
また初心者向けに記事を書いている関係上、冗長な言い回しになっていますがご了承下さい。
ダメだった手順(コマンド)
OS:Windows
コンソール:PowerShell
1、まずパス無しrootでログインできない事を確認。
> mysql -uroot
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
2、root権限で設定したパスでログイン。
> mysql -u root -p
Enter password: **********
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 15
Server version: 5.7.28-log MySQL Community Server (GPL)
Copyright (c) 2000, 2019, 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>
↑これが出ればログインは成功。
3、調べたコマンドを実行(rootのパスを変更)
mysql> use mysql;
Database changed
mysql> update user set password='' where User='root';
ERROR 1054 (42S22): Unknown column 'password' in 'field list'
updateでエラーが出ました・・・
ちなみに参考にした記事は以下です。どの記事でも同じような感じで変更できています。
https://qiita.com/saicologic/items/4c103a399cffa4432635
http://at284km.hatenablog.com/entry/2015/07/11/065931
https://blog.codecamp.jp/root-password
mysqlという名前のDBのuserテーブルに対して変更をかけましたが、今回はUnknown column 'password'が返されました。
passwordというカラムが見つからないと言っております。
では実際にテーブル参照していきます。
mysql> select * from user;
+-----------+---------------+-------------+-------------+-------------+-------------+-------------+-----------+-------------+---------------+--------------+-----------+------------+-----------------+------------+------------+--------------+------------+-----------------------+------------------+--------------+-----------------+------------------+------------------+----------------+---------------------+--------------------+------------------+------------+--------------+------------------------+----------+------------+-------------+--------------+---------------+-------------+-----------------+----------------------+-----------------------+-------------------------------------------+------------------+-----------------------+-------------------+----------------+
| Host | User | Select_priv | Insert_priv | Update_priv | Delete_priv | Create_priv | Drop_priv | Reload_priv | Shutdown_priv | Process_priv | File_priv | Grant_priv | References_priv | Index_priv | Alter_priv | Show_db_priv | Super_priv | Create_tmp_table_priv | Lock_tables_priv | Execute_priv | Repl_slave_priv | Repl_client_priv | Create_view_priv | Show_view_priv | Create_routine_priv | Alter_routine_priv | Create_user_priv | Event_priv | Trigger_priv | Create_tablespace_priv | ssl_type | ssl_cipher | x509_issuer | x509_subject | max_questions | max_updates | max_connections | max_user_connections | plugin | authentication_string | password_expired | password_last_changed | password_lifetime | account_locked |
+-----------+---------------+-------------+-------------+-------------+-------------+-------------+-----------+-------------+---------------+--------------+-----------+------------+-----------------+------------+------------+--------------+------------+-----------------------+------------------+--------------+-----------------+------------------+------------------+----------------+---------------------+--------------------+------------------+------------+--------------+------------------------+----------+------------+-------------+--------------+---------------+-------------+-----------------+----------------------+-----------------------+-------------------------------------------+------------------+-----------------------+-------------------+----------------+
| localhost | root | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | | | | | 0 | 0 | 0 | 0 | mysql_native_password | *2C1BFAE4C28F44CFF5C5B84806BF2DD02FB39297 | N | 2020-01-06 16:35:27 | NULL | N |
| localhost | mysql.session | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | Y | N | N | N | N | N | N | N | N | N | N | N | N | N | | | | | 0 | 0 | 0 | 0 | mysql_native_password | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | N | 2020-01-06 16:35:23 | NULL | Y |
| localhost | mysql.sys | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | | | | | 0 | 0 | 0 | 0 | mysql_native_password | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | N | 2020-01-06 16:35:23 | NULL | Y |
+-----------+---------------+-------------+-------------+-------------+-------------+-------------+-----------+-------------+---------------+--------------+-----------+------------+-----------------+------------+------------+--------------+------------+-----------------------+------------------+--------------+-----------------+------------------+------------------+----------------+---------------------+--------------------+------------------+------------+--------------+------------------------+----------+------------+-------------+--------------+---------------+-------------+-----------------+----------------------+-----------------------+-------------------------------------------+------------------+-----------------------+-------------------+----------------+
3 rows in set (0.00 sec)
mysql>
ちょっと長ったらしい表示結果ですが、今回変更したいpasswordというカラムが見当たりません。
念のため以下で確認します。
mysql> select password from user;
ERROR 1054 (42S22): Unknown column 'password' in 'field list'
やはりなさそうです。
なので別の方法でやっていくことにします。
今回変更できた手順(コマンド)
1、set passwordでroot@localhostというアドレスに対して直接変更をかける。
mysql> set password for root@localhost=password('');
Query OK, 0 rows affected, 1 warning (0.00 sec)
Query OK・・・どうやら出来た見たいですね。
2、パス無しでログイン出来るかを確認。
・一度quitでmysqlを抜けます。
mysql> quit
Bye
PS C:\WINDOWS\system32>
これでpowershellの実行環境に戻りました。
・パスワードオプション無しでrootでmysqlにログインします。
> mysql -uroot
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 18
Server version: 5.7.28-log MySQL Community Server (GPL)
Copyright (c) 2000, 2019, 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>
はい、無事完了です![]()
ちなみにこちらの記事を参考にさせて頂きました。ありがとうございます。