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 2.1KB

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