Browse Source

Merge pull request #259 from rangerz/mysql

Add bin/dbdump and improve bin/mysql
Mark Shust 4 years ago
parent
commit
0fa2c0de65
5 changed files with 26 additions and 11 deletions
  1. 13 6
      README.md
  2. 2 0
      compose/bin/dbdump
  3. 7 1
      compose/bin/mysql
  4. 3 4
      compose/bin/n98-magerun2
  5. 1 0
      compose/env/db.env

+ 13 - 6
README.md

@@ -205,7 +205,7 @@ bin/composer install
 bin/copyfromcontainer vendor
 
 # Import existing database:
-bin/clinotty mysql -hdb -umagento -pmagento magento < existing/magento.sql
+bin/mysql < backups/magento.sql
 
 # Update database connection details to use the above Docker MySQL credentials:
 # Also note: creds for the MySQL server are defined at startup from env/db.env
@@ -262,7 +262,8 @@ You'll now have an updated `bin/update` helper script, and can run it to update
 - `bin/fixperms`: This will fix filesystem permissions within the container.
 - `bin/grunt`: Run the grunt binary. Ex. `bin/grunt exec`
 - `bin/magento`: Run the Magento CLI. Ex: `bin/magento cache:flush`
-- `bin/mysql`: Run the MySQL CLI with database config from env/db.env. Ex `bin/mysql -e "EXPLAIN core_config_data"`
+- `bin/mysql`: Run the MySQL CLI with database config from `env/db.env`. Ex. `bin/mysql -e "EXPLAIN core_config_data"` or`bin/mysql < backups/magento.sql`
+- `bin/mysqldump`: Backup the Magento database. Ex. `bin/mysqldump > backups/magento.sql`
 - `bin/n98-magerun2`: Access the n98 magerun CLI. Ex: `bin/n98-magerun2 dev:console`
 - `bin/node`: Run the node binary. Ex. `bin/node --version`
 - `bin/npm`: Run the npm binary. Ex. `bin/npm install`
@@ -291,16 +292,22 @@ You'll now have an updated `bin/update` helper script, and can run it to update
 
 The hostname of each service is the name of the service within the `docker-compose.yml` file. So for example, MySQL's hostname is `db` (not `localhost`) when accessing it from within a Docker container. Elasticsearch's hostname is `elasticsearch`.
 
-Here's an example of how to connect to the MySQL cli tool of the Docker instance:
+To connect to the MySQL CLI tool of the Docker instance, run:
 
 ```
-bin/cli mysql -h db -umagento -pmagento magento
+bin/mysql
 ```
 
-You can use the `bin/clinotty` helper script to import a database. This example uses the root MySQL user, and looks for the `dbdump.sql` file in your local host directory:
+You can use the `bin/mysql` script to import a database, for example a file stored in your local host directory at `backups/magento.sql`:
 
 ```
-bin/clinotty mysql -h db -u root -pmagento magento < dbdump.sql
+bin/mysql < backups/magento.sql
+```
+
+You also can use `bin/mysqldump` to export the database. The file will appear in your local host directory at `backups/magento.sql`:
+
+```
+bin/mysqldump > backups/magento.sql
 ```
 
 ### Composer Authentication

+ 2 - 0
compose/bin/dbdump

@@ -0,0 +1,2 @@
+#!/bin/bash
+bin/n98-magerun2 db:dump --stdout "$@"

+ 7 - 1
compose/bin/mysql

@@ -1,3 +1,9 @@
 #!/bin/bash
 source env/db.env
-bin/cli mysql -hdb -u${MYSQL_USER} -p${MYSQL_PASSWORD} ${MYSQL_DATABASE} "$@"
+if [ -t 0 ]; then
+  # Need tty to run mysql shell
+  bin/cli mysql -h${MYSQL_HOST} -u${MYSQL_USER} -p${MYSQL_PASSWORD} ${MYSQL_DATABASE} "$@"
+else
+  # Read from stdin, ex: bin/mysql < dbdump.sql
+  bin/clinotty mysql -h${MYSQL_HOST} -u${MYSQL_USER} -p${MYSQL_PASSWORD} ${MYSQL_DATABASE} "$@"
+fi

+ 3 - 4
compose/bin/n98-magerun2

@@ -1,8 +1,7 @@
 #!/bin/bash
 if ! bin/clinotty ls bin/n98-magerun2.phar 1> /dev/null 2>&1; then
-    bin/clinotty curl -O https://files.magerun.net/n98-magerun2.phar
-    bin/clinotty chmod +x n98-magerun2.phar
-    bin/clinotty mkdir -p bin
-    bin/clinotty mv n98-magerun2.phar bin/n98-magerun2.phar
+  bin/clinotty mkdir -p bin
+  bin/clinotty curl https://files.magerun.net/n98-magerun2.phar -o bin/n98-magerun2.phar
+  bin/clinotty chmod +x bin/n98-magerun2.phar
 fi
 bin/cli bin/n98-magerun2.phar "$@"

+ 1 - 0
compose/env/db.env

@@ -1,3 +1,4 @@
+MYSQL_HOST=db
 MYSQL_ROOT_PASSWORD=magento
 MYSQL_DATABASE=magento
 MYSQL_USER=magento