【问题标题】:Automate MYSQL CREATE DATABASE on terminal在终端上自动化 MYSQL CREATE DATABASE
【发布时间】:2018-07-01 06:53:55
【问题描述】:

我正在运行我创建的用于下载和安装 WordPress 的脚本。为了节省更多时间,我想打开 MAMP MYSQL 并创建一个新数据库,如下所示:

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

我的其余功能:

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;
}

如何将 MYSQL 行添加到此函数并使其按预期工作?

谢谢

【问题讨论】:

标签: mysql wordpress shell terminal


【解决方案1】:

为什么不使用:

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

mysqladmin 是一个命令行工具,它是标准 MySQL 客户端软件的一部分。它应该出现在有mysql 工具的任何地方。

您可能想阅读https://dev.mysql.com/doc/refman/5.7/en/mysqladmin.html

另一种选择是将 CREATE DATABASE 作为参数传递给mysql

/Applications/MAMP/Library/bin/mysql ... -e "CREATE DATABASE mydatabase"

【讨论】:

    猜你喜欢
    • 2015-12-10
    • 1970-01-01
    • 2010-11-16
    • 2018-03-14
    • 2011-07-22
    • 1970-01-01
    • 2016-08-31
    • 2020-02-07
    • 1970-01-01
    相关资源
    最近更新 更多