LinuxでMySQLパスワードを変更する

1.管理者がLinuxにログインします

2.設定ファイルにスキップ権限を追加します

2.1構成ファイルを編集します。

vim /etc/my.cnf

2.2ファイルの最終行に次のように入力します。

skip-grant-tables

2.3 保存

:wq

2.4 MySQLサービスを再起動します

systemctl restart mysqld

3. rootアカウントでMySQLにログインします

mysql -uroot -p

パスワードの入力を求め、Enterキーを押します。

4.パスワードを変更する

4.1運用データベースを指定する

use mysql

4.2パスワードを123456に更新する

MySQL 5.7より前:

update user set password=password('123456') where user='root';

MySQL 5.7以降:

update user set authentication_string=password('123456') where user='root';

4.3権限の更新

flush privileges;

4.4 MySQLを終了する

exit;

5.設定ファイルを復元します

5.1構成ファイルを編集します。

vim /etc/my.cnf

5.2コメントの前の行:

# skip-grant-tables

5.3 保存

:wq

5.4 MySQLサービスを再起動します

systemctl restart mysqld
420件の元の記事を公開しました 143件のいいね 890,000回の閲覧

おすすめ

転載: blog.csdn.net/jeikerxiao/article/details/104832992