Skip to content

Instantly share code, notes, and snippets.

@taiar
Forked from elialejandro/AutoinstallMYSQL.sh
Created April 27, 2020 11:36
Show Gist options
  • Save taiar/389aa75f8a4d9b09dbb1ee09f523b391 to your computer and use it in GitHub Desktop.
Save taiar/389aa75f8a4d9b09dbb1ee09f523b391 to your computer and use it in GitHub Desktop.
MySQL 5.7 No directory, logging in with HOME=/
# Install MySQL
mysql_config_file="/etc/mysql/my.cnf"
echo "mysql-server mysql-server/root_password password secret" | sudo debconf-set-selections
echo "mysql-server mysql-server/root_password_again password secret" | sudo debconf-set-selections
apt-get -y install mysql-client mysql-server
sed -i "s/bind-address\s*=\s*127.0.0.1/bind-address = 0.0.0.0/" ${mysql_config_file}
usermod -d /var/lib/mysql/ mysql
service mysql start
# Allow root access from any host
echo "GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'secret' WITH GRANT OPTION" | mysql -u root --password=secret
echo "GRANT PROXY ON ''@'' TO 'root'@'%' WITH GRANT OPTION" | mysql -u root --password=secret
service mysql restart

Stop MYSQL service:

sudo service mysql stop

Change home directory of mysql from nonexistent to original directory where it is supposed to be

sudo usermod -d /var/lib/mysql/ mysql

Start MYSQL service

sudo service mysql start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment