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.

i.mysql.centos.sh 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #!/bin/bash
  2. # Update the system
  3. echo "Updating the system..."
  4. sudo yum update -y
  5. # Install the MySQL repository
  6. echo "Installing MySQL repository..."
  7. sudo yum localinstall -y https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
  8. # Enable the MySQL repository
  9. echo "Enabling MySQL repository..."
  10. sudo yum-config-manager --enable mysql80-community
  11. # Install MySQL server
  12. echo "Installing MySQL server..."
  13. sudo yum install -y mysql-server
  14. # Start MySQL service
  15. echo "Starting MySQL service..."
  16. sudo systemctl start mysqld
  17. # Enable MySQL to start on boot
  18. echo "Enabling MySQL to start on boot..."
  19. sudo systemctl enable mysqld
  20. # Get the temporary MySQL root password
  21. TEMP_PASS=$(sudo grep 'temporary password' /var/log/mysqld.log | tail -n 1 | awk '{print $NF}')
  22. echo "Temporary MySQL root password: $TEMP_PASS"
  23. # Secure MySQL installation (you can modify the commands for automation if desired)
  24. echo "Securing MySQL installation..."
  25. sudo mysql_secure_installation <<EOF
  26. y
  27. $TEMP_PASS
  28. newpassword
  29. newpassword
  30. y
  31. y
  32. y
  33. y
  34. EOF
  35. # Output MySQL status
  36. echo "MySQL installation completed successfully."
  37. # You can log into MySQL by running:
  38. echo "You can log into MySQL with: mysql -u root -p"
  39. echo "Creating or Updating CIHSR User with remote access"
  40. # Prompt for MySQL root password
  41. read -sp "Enter MySQL root password: " MYSQL_PASSWORD
  42. echo
  43. mysql -u root -p"$MYSQL_PASSWORD" <<EOF
  44. CREATE USER IF NOT EXISTS 'cihsr'@'%' IDENTIFIED BY 'Cihsr@123456';
  45. GRANT ALL PRIVILEGES ON *.* TO 'cihsr'@'%' WITH GRANT OPTION;
  46. FLUSH PRIVILEGES;
  47. ALTER USER 'cihsr'@'%' IDENTIFIED BY 'Cihsr@123456';
  48. EOF
  49. if [ $? -eq 0 ]; then
  50. echo "User 'cihsr' has been successfully created or updated."
  51. else
  52. echo "Error: Failed to create or update user 'cihsr'."
  53. fi
  54. sudo firewall-cmd --zone=public --add-port=3306/tcp --permanent
  55. sudo firewall-cmd --reload