nystudio107 / craft-scripts

Shell scripts to manage database backups, asset backups, file permissions, asset syncing, cache clearing, and database syncing between Craft CMS environments
https://nystudio107.com/
MIT License
362 stars 61 forks source link

DDEV pull-database not connecting or not properly pulling + restoring remote #66

Closed stevehurst closed 1 year ago

stevehurst commented 1 year ago

I converted some local dev sites from Nitro to DDEV and I'm having issues running the 'pull-database' script. Here are my database details when running ddev describe:

│ db       │ OK   │ InDocker: db:3306                                       │ mysql:8.0          │
│            │          │ Host: 127.0.0.1:60810                                   │ User/Pass: 'db/db' │
│            │          │                                                                        │ or 'root/root'  
  1. If I run with the indocker settings that are in my .env file, I get a database connection error
  2. If I customize the .env.sh to use the host settings, I can connect and it looks like it connects and works (see below), but the remote database is not restored over my local database
mysqldump: [Warning] Using a password on the command line interface can be insecure.
mysqldump: Couldn't execute 'FLUSH TABLES': Access denied; you need (at least one of) the RELOAD or FLUSH_TABLES privilege(s) for this operation (1227)
mysqldump: [Warning] Using a password on the command line interface can be insecure.
Enter passphrase for key '/Users/stevehurst/.ssh/id_rsa': 
av07952-kcraft-db-dump-20230320.sql.gz                                                                  100%   42MB   8.4MB/s   00:05    
mysqldump: [Warning] Using a password on the command line interface can be insecure.
mysqldump: [Warning] Using a password on the command line interface can be insecure.
*** Backed up local database to /tmp/db-db-backup-20230320.sql.gz
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 1062 (23000) at line 41: Duplicate entry '1' for key 'announcements.PRIMARY'
*** Restored local database from /tmp/av07952-kcraft-db-dump-20230320.sql.gz

Are there specific settings changes needed to the .env.sh file for mysql commands when running Craft on DDEV?

# Local database constants; default port for mysql is 3306, default port for postgres is 5432
# This pulls values from your local .env file
LOCAL_DB_NAME="db"
LOCAL_DB_PASSWORD="root"
LOCAL_DB_USER="root"
LOCAL_DB_HOST="127.0.0.1"
LOCAL_DB_PORT="60810"
LOCAL_DB_SCHEMA="public"

# The `mysql` and `mysqldump` commands to run locally
LOCAL_MYSQL_CMD="mysql"
LOCAL_MYSQLDUMP_CMD="mysqldump"
khalwat commented 1 year ago

You have to either run the scripts inside of the container (and ensure there is routing to the outside world), or modify the scripts to access the db container.

Example here:

https://github.com/nystudio107/devmode/blob/develop/scripts/docker_pull_db.sh