Skip to content

Instantly share code, notes, and snippets.

@saxenap
Last active March 3, 2020 01:01
Show Gist options
  • Save saxenap/e16392e884c603828e2cc9c901305fd5 to your computer and use it in GitHub Desktop.
Save saxenap/e16392e884c603828e2cc9c901305fd5 to your computer and use it in GitHub Desktop.
#!/bin/bash
# rm -rf mysql8_installation && wget -O mysql8_installation https://gist.githubusercontent.com/saxenap/e16392e884c603828e2cc9c901305fd5/raw/ && chmod 777 mysql8_installation && ./mysql8_installation
wget https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
sudo yum localinstall -y mysql80-community-release-el7-3.noarch.rpm
sudo yum install -y mysql-community-server
sudo systemctl enable mysqld.service
sudo systemctl start mysqld.service
mysql_new_root_pass=Password01!
mysql_temp_pass=$(grep 'A temporary password is generated for root' /var/log/mysqld.log | cut -d ":" -f4 | awk '{$1=$1};1')
#grep 'temporary password' /var/log/mysqld.log | awk '{print $13}'
mysql -u root -p$mysql_temp_pass -e "ALTER USER 'root'@'localhost' IDENTIFIED BY $mysql_new_root_pass;"
mysql -u root -p$mysql_temp_pass -e "DELETE FROM mysql.user WHERE User='';"
mysql -u root -p$mysql_temp_pass -e "DELETE FROM mysql.user WHERE User='root' AND Host NOT IN ('localhost', '127.0.0.1', '::1');"
mysql -u root -p$mysql_temp_pass -e "DROP DATABASE IF EXISTS test;"
mysql -u root -p$mysql_temp_pass -e "DELETE FROM mysql.db WHERE Db='test' OR Db='test\\_%';"
mysql -u root -p$mysql_temp_pass -e "FLUSH PRIVILEGES;"
# Use these if getting an error from Mysql
# CREATE USER 'foo'@'localhost' IDENTIFIED WITH mysql_native_password BY 'bar';
# GRANT ALL PRIVILEGES ON database_name.* TO'foo'@'localhost';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment