Skip to content

Instantly share code, notes, and snippets.

@berliozd
Created October 18, 2016 15:07
Show Gist options
  • Select an option

  • Save berliozd/d65cc5caf3b997239452f7ecfd15c55f to your computer and use it in GitHub Desktop.

Select an option

Save berliozd/d65cc5caf3b997239452f7ecfd15c55f to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# Variables
#------------
mysqlUser='root'
mysqlPass='password'
mysqlAppDbName='ltdc'
mysqlAppDbUser='ltdc'
mysqDumpFile='/home/didier/src/tmp/ltdc/DB-PROD-2016-10-13-17h43.sql'
vHostName='ltdc'
createDb=true
deleteDb=true
# delete database
if ${deleteDb}; then
mysql -u ${mysqlUser} -p"${mysqlPass}" << EOF
DROP DATABASE ${mysqlAppDbName};
DROP USER '${mysqlAppDbUser}'@'localhost';
EOF
fi
# create database
if ${createDb}; then
mysql -u ${mysqlUser} -p"${mysqlPass}" << EOF
CREATE DATABASE ${mysqlAppDbName};
CREATE USER '${mysqlAppDbUser}'@'localhost' IDENTIFIED BY '${mysqlAppDbUser}';
GRANT ALL PRIVILEGES ON ${mysqlAppDbName}. * TO '${mysqlAppDbUser}'@'localhost';
EOF
fi
# Import database
mysql -u ${mysqlUser} -p"${mysqlPass}" ${mysqlAppDbName} < ${mysqDumpFile}
mysql -u ${mysqlUser} -p"${mysqlPass}" << EOF
use ${mysqlAppDbName};
update core_config_data set value = 'http://${vHostName}.local/' where path like '%secure/base_url%';
update core_config_data set value = 'http://${vHostName}.local/' where path like '%secure/base_link_url%';
update core_config_data set value = 'http://${vHostName}.local/skin/' where path like '%secure/base_skin_url%';
update core_config_data set value = 'http://${vHostName}.local/media/' where path like '%secure/base_media_url%';
update core_config_data set value = 'http://${vHostName}.local/js/' where path like '%secure/base_js_url%';
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment