Skip to content

Instantly share code, notes, and snippets.

@mindfullsilence
Created July 1, 2024 04:30
Show Gist options
  • Save mindfullsilence/e137cf34072f2db7bd982fbfea927ed0 to your computer and use it in GitHub Desktop.
Save mindfullsilence/e137cf34072f2db7bd982fbfea927ed0 to your computer and use it in GitHub Desktop.
Error at line 1 in file: importing database "Unknown Command '\-'"
#!/bin/bash
DB_BACKUP_DIR_ROOT="$HOME/Desktop/mysql_backup"
# Create the backup directory
mkdir -p $DB_BACKUP_DIR_ROOT
# Backup each db in the server, skip schema dbs though
for db in $(mysql -u root -Bse 'show databases'|egrep -vi 'information_schema|performance_schema|user')
do
mysqldump -u root --databases $db > "$DB_BACKUP_DIR_ROOT/$db.sql"
done

Fixing https://mariadb.org/mariadb-dump-file-compatibility-change/ Error is caused by an incompatibility when trying to import a mariadb databased into a mysql server. I fixed this by swapping mysql on my macbook with mariadb (the live server runs mariadb - switching it to mysql wasn't an option).

Requires homebrew. Not meant for running on an actual server.

  1. Added the shell scripts to desktop and gave them execute permissions: a. chmod +x ~/Desktop/backup.sh && chmod +x ~/Desktop/restore.sh
  2. Make a backup of all databases (to add them to mariadb in step 7) with cd ~/Desktop && ./backup.sh
  3. Double check all databases are in ~/Desktop/mysql_backups/ folder
  4. Stopped all mysql services in dbngin
  5. removed any homebrew mysql installations: a. brew uninstall --force mariadb mysql b. rm -rf /opt/homebrew/etc/my.cnf* c. rm -rf /opt/homebrew/var/mysql
  6. Install fresh mariadb a. brew install mariadb
  7. If you usually use the root user with blank password during local dev, you need to update in mysql: a. sudo mysql -u root (input your mac password) b. SET PASSWORD = PASSWORD(''); (from inside mysql command line) c. exit; (from inside mysql command line to go back to terminal)
  8. Add the databases to mariadb cd ~/Desktop && ./restore.sh
#!/bin/bash
DB_BACKUP_DIR_ROOT="$HOME/Desktop/mysql_backup/*.sql"
# Restore all dbs from backup directory
for database in $DB_BACKUP_DIR_ROOT
do
sed -i='' 's/utf8mb4_0900_ai_ci/utf8mb4_unicode_520_ci/g' $database
mysql -u root < $database
done;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment