202303181450MySQL 8 初始化 - 設定 root 密碼卻落入無限輪迴 Endless loop in mysql_secure_installation
使用 $ sudo mysql_secure_installation 做 mysql 8 version 初始化 卻在 Estimated strength of the password: 100 Change the password for root ? 這裡無限輪迴 Endless loop,一直設定 mysql root 密碼,還不能 ctrl-C 中斷
解決方式
簡單說,先以 sudo mysql 進入,再更換掉 mysql root 密碼,步驟請參考
~$ sudo mysql_secure_installation -p
[sudo] password for hello:
Enter password: [sudo 的密碼]
Securing the MySQL server deployment.
The 'validate_password' component is installed on the server.
The subsequent steps will run with the existing configuration
of the component.
Using existing password for root.
Estimated strength of the password: 100
Change the password for root ? ((Press y|Y for Yes, any other key for No) : no
// 上面這行很重要,請選擇 No ,如果 yes 就進入五道輪迴了,連 Ctrl-C 都不給你機會,只能重新連線
// 下面也不特別,就跟正常初始化一樣
... skipping.
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.
Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
Success.
Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y
Success.
By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.
Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y
- Dropping test database...
Success.
- Removing privileges on test database...
Success.
Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.
Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
Success.
All done!
// 然後使用 sudo 進入
$ sudo mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 25
Server version: 8.0.32-0ubuntu0.22.04.2 (Ubuntu)
Copyright (c) 2000, 2023, Oracle and/or its affiliates.
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 Root 密碼變更
mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password by 'mysql_root_password';
mysql> exit
// 變更完 Mysql Root 密碼,就可以以自己設定的密碼登入了
$ mysql -u root -p
就可以跟以前一樣繼續操作 MySQL。
~END