You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

mysql.init.sh 737B

123456789101112131415161718192021222324
  1. #!/bin/bash
  2. # Prompt the user for the MySQL root password and new password
  3. echo "Enter MySQL root password:"
  4. read -s ROOT_PASSWORD
  5. # Step 6: Change authentication plugin to mysql_native_password
  6. echo "Changing authentication plugin for MySQL root user..."
  7. mysql -u root -p"$ROOT_PASSWORD" <<-EOF
  8. USE mysql
  9. ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '$ROOT_PASSWORD';
  10. FLUSH PRIVILEGES;
  11. EOF
  12. # Step 8: Restart MySQL normally
  13. echo "Restarting MySQL service..."
  14. sudo systemctl restart mysqld
  15. # Step 9: Test MySQL login with new password
  16. echo "Testing MySQL login..."
  17. mysql -u root -p"$NEW_PASSWORD" -e "SHOW DATABASES;"
  18. echo "MySQL root user authentication plugin has been updated successfully."