#! /bin/sh . /usr/src/k_framework/main.sh SCRIPT_NAME="MySQL 5.7 Install" VERSION="1.1.2" k_start k_mysql_version if [[ $MYSQL_VERSION1 == "5" && $MYSQL_VERSION2 == "7" ]]; then report "MySQL 5.7 is already installed" 3 k_exit 0 fi # Installing the necessary packets and starting/activating the mysqld service. k_centos_version if (( centos_version != 6 )); then # centos 7 #yum -y localinstall https://dev.mysql.com/get/mysql80-community-release-el7-1.noarch.rpm cd /usr/src/ wget https://dev.mysql.com/get/mysql80-community-release-el7-1.noarch.rpm rpm -Uvh mysql80-community-release-el7-1.noarch.rpm yum -y --nogpgcheck --disablerepo=mysql80-community --enablerepo=mysql57-community install mysql-community-server mysql-community-devel rm -fr /usr/src/mysql80-community-release-el7-1.noarch.rpm systemctl start mysqld.service ## use restart after update systemctl enable mysqld.service report "MySQL 5.7 installed" 0 else # centos 6 cd /usr/src wget https://dev.mysql.com/get/mysql80-community-release-el6-1.noarch.rpm rpm -ivh mysql80-community-release-el6-1.noarch.rpm yum -y --disablerepo=mysql80-community --enablerepo=mysql57-community install mysql-community-server mysql-community-devel # Import correct rpm keys. Asterisk install (/usr/src/asterisk-15/contrib/scripts/install_prereq install) later fails without this rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022 service mysqld start chkconfig --level 345 mysqld on service mysqld status # Checking if mysql service is up. if service mysqld status | grep "is running"; then report "MySQL 5.7 is running" 0 else report "MySQL 5.7 is not running. Please check logs for troubleshooting" 1 k_exit 1 fi fi # --- Initial configuration --- report "Starting initial MySQL configuration" 3 # Retrieve tmp password set for MySQL root. tmp_psw=`grep 'A temporary password is generated for root@localhost' /var/log/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 5.7 configuration done. Root password set to $psw" 0 /bin/cp -fr /usr/src/k_framework/helpers/mysql/5.7/my.cnf /etc/my.cnf k_service_restart mysqld # Checking if mysql service is up if k_service_is_running mysqld; then report "MySQL 5.7 installed and configured" 0 else report "MySQL 5.7 is not running. Please check logs for troubleshooting" 1 EXIT_CODE=1 fi k_exit $EXIT_CODE