0

I'm running a script I have created that downloads and installs WordPress. To save more time I wanted to open MAMP MYSQL and create a new database like so:

/Applications/MAMP/Library/bin/mysql --host=localhost -uroot -proot
CREATE DATABASE $1; // passed into the function as argument
exit; // to get out of MYSQL 

The rest of my function:

wordpress() {
  cd /Volumes/example/example/Web/dev;  mkdir $1;
  cd $1;
  curl -O https://wordpress.org/latest.tar.gz;
  tar -xvzf latest.tar.gz;
  mv wordpress/* .;
  rmdir wordpress/;
  rm latest.tar.gz;
  cp wp-config-sample.php wp-config.php;
  vim -s /Volumes/example/example/Web/dev/db_overwrite.txt wp-config.php;
  curl -O https://downloads.wordpress.org/plugin/wp-super-cache.latest-stable.zip;
  curl -O https://downloads.wordpress.org/plugin/wp-migrate-db.latest-stable.zip;
  curl -O https://downloads.wordpress.org/plugin/contact-form-7.latest-stable.zip;
  curl -O https://downloads.wordpress.org/plugin/wordpress-seo.latest-stable.zip
  mv wp-super-cache.latest-stable.zip wp-migrate-db.latest-stable.zip contact-form-7.latest-stable.zip wordpress-seo.latest-stable.zip wp-content/plugins;  
  cd wp-content/plugins;
  cp /Volumes/example/example/Web/Plugins/advanced-custom-fields-pro.zip .
  unzip advanced-custom-fields-pro.zip;
  unzip wp-super-cache.latest-stable.zip;
  unzip wp-migrate-db.latest-stable.zip;
  unzip contact-form-7.latest-stable.zip;
  unzip wordpress-seo.latest-stable.zip;
  rm wp-super-cache.latest-stable.zip wp-migrate-db.latest-stable.zip contact-form-7.latest-stable.zip wordpress-seo.latest-stable.zip;
  cd ../themes;
  git clone https://github.com/example/my-template;
}

How would I add the MYSQL lines to this function and make it work as intended?

Thanks

3
  • If you're on Linux, read this for instance: shellhacks.com/mysql-run-query-bash-script-linux-command-line Commented Jan 22, 2018 at 15:37
  • Or this one: stackoverflow.com/questions/7616520/… Commented Jan 22, 2018 at 15:39
  • @Roadowl these are helpful but I also wanted to dynamically create the database name by argument pass to the function like so: wordpress my_wordpress Commented Jan 22, 2018 at 15:59

1 Answer 1

0

Why not use:

/Applications/MAMP/Library/bin/mysqladmin -uroot -proot create mydatabase

mysqladmin is a command-line tool that is part of the standard MySQL client software. It should be present everywhere that the mysql tool is present.

You might like to read https://dev.mysql.com/doc/refman/5.7/en/mysqladmin.html

Another alternative is to pass the CREATE DATABASE as an argument to mysql:

/Applications/MAMP/Library/bin/mysql ... -e "CREATE DATABASE mydatabase"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.