#! /bin/bash . /usr/src/k_framework/main.sh SCRIPT_NAME="MySQL 8 Configure" VERSION="1.0.5" k_start k_mysql_version k_detect_os if [[ $centos_version == 7 || $ROCKY9 == 1 ]]; then if [[ $MYSQL_VERSION1 != 8 ]]; then "MySQL version $MYSQL_VERSION. Expected v8" 1 EXIT_CODE=1 k_exit 1 fi k_service_enable mysqld.service k_service_start mysqld.service report "MySQL $MYSQL_VERSION activated" 0 else report "Centos 7 / Rocky 9 required. OS: $OS $DIST" 1 EXIT_CODE=1 k_exit 1 fi # --- Initial configuration --- report "Starting initial MySQL configuration" 3 # delete anonymous user mysql -u root -e "DELETE FROM mysql.user WHERE User!='root' AND Host NOT IN ('localhost', '127.0.0.1', '::1');" # mysql -u root -e "DROP DATABASE test" # Can't drop database 'test'; database doesn't exist mysql -u root -e "SET PASSWORD = 'kolmisoft';" mysql -u root -pkolmisoft -e "FLUSH PRIVILEGES" # Retrieve tmp password set for MySQL root. #tmp_psw=`grep 'A temporary password is generated for root@localhost' /var/log/mysql/mysqld.log |tail -1|awk '{ print $11 }'` # Temporary root password to disable hard passwords. #tmp_psw2="Kxslkhx.as99" # Default mysql root password for easy management. #psw="kolmisoft" # Change root password from assigned one to some random hard password so we could proceed to the next step. #MYSQL_PWD=$tmp_psw mysql -u root --connect-expired-password -e "SET PASSWORD = PASSWORD('$tmp_psw2');" # Disable strict password requirements. #MYSQL_PWD=$tmp_psw2 mysql -u root -e "uninstall plugin validate_password;" # Set constant password for MySQL root. #MYSQL_PWD=$tmp_psw2 mysql -u root -e "SET PASSWORD = PASSWORD('$psw');" # Kill the anonymous users #MYSQL_PWD=$psw mysql -u root -e "DROP USER ''@'localhost'" # Because our hostname varies we'll use some Bash magic here. #MYSQL_PWD=$psw mysql -u root -e "DROP USER ''@'$(hostname)'" # Kill off the demo database #MYSQL_PWD=$psw mysql -u root -e "DROP DATABASE test" # Disallow remote login for root #MYSQL_PWD=$psw mysql -u root -e "DELETE FROM mysql.user WHERE User='root' AND Host NOT IN ('localhost', '127.0.0.1', '::1');" # Make our changes take effect #MYSQL_PWD=$psw mysql -u root -e "FLUSH PRIVILEGES" report "Initial MySQL configuration done" 0 /bin/cp -fr /usr/src/k_framework/helpers/mysql/8/my.cnf /etc/my.cnf # Add PrivateTmp override # https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/9/html/using_systemd_unit_files_to_customize_and_optimize_your_system/assembly_working-with-systemd-unit-files_working-with-systemd#proc_modifying-existing-unit-files_assembly_working-with-systemd-unit-files mkdir -p /etc/systemd/system/mysqld.service.d/ if [[ ! -e /etc/systemd/system/mysqld.service.d/custom.conf ]]; then echo -e "[Service]\nPrivateTmp=false" > /etc/systemd/system/mysqld.service.d/custom.conf systemctl daemon-reload fi k_service_restart mysqld # Checking if mysql service is up if k_service_is_running mysqld; then report "MySQL $MYSQL_VERSION installed and configured" 0 else report "MySQL $MYSQL_VERSION is not running. Please check logs for troubleshooting" 1 EXIT_CODE=1 fi k_exit $EXIT_CODE