mac忘れmysqlパスワードソリューション

1323 ワード

mysql-5.7.28
デフォルトのインストールパス /usr/local/mysql
1.mysqlプロセスを閉じる
sudo /usr/local/mysql/support-files/mysql.server stop

2.--skip-grant-tables方式でmysqlを起動する
sudo /usr/local/mysql/support-files/mysql.server start --skip-grant-tables --user=root

3.パスワードなしでmysqlに接続
/usr/local/mysql/bin -uroot

4.rootパスワードの更新
  5.7バージョン以上:
mysql>update mysql.user set authentication_string=password('   ') where user='root' and Host='localhost';

  5.7次のバージョン:
mysql>update mysql.user set password=password('   ') where user='root' and host='localhost';

5.パスワードの変更を有効にするには、権限テーブルをリフレッシュします.
mysql>flush privileges;

6.mysqlを再起動
sudo /usr/local/mysql/support-files/mysql.server restart

7.パスワード付きログイン
/usr/local/mysql/bin -uroot -p,//           

8.この方式でパスワードを変更した後、再度ログインするとシステムはパスワードを強制的に変更する
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.

9.パスワードの変更
set password for 'root'@'localhost' = password('   ');