sudo mysql -e "ALTER USER 'root'@'localhost' IDENTIFIED WITH caching_sha2_password BY 'secret';"
Set a password for the root account
Switches root to password authentication with the modern caching_sha2_password plugin, the recommended step right after a fresh install. Run it via sudo mysql while socket auth still works. Use a strong password, not the demo value.
Looking for more? Search all 7,657 commands — works offline, in English or Spanish, and fixes typos.