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 723B

1234567891011121314151617181920212223
  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. ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '$ROOT_PASSWORD';
  9. FLUSH PRIVILEGES;
  10. EOF
  11. # Step 8: Restart MySQL normally
  12. echo "Restarting MySQL service..."
  13. sudo systemctl restart mysqld
  14. # Step 9: Test MySQL login with new password
  15. echo "Testing MySQL login..."
  16. mysql -u root -p"$NEW_PASSWORD" -e "SHOW DATABASES;"
  17. echo "MySQL root user authentication plugin has been updated successfully."