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