Skip to content

Instantly share code, notes, and snippets.

@davidalger
Last active July 22, 2020 15:56
Show Gist options
  • Save davidalger/5806612 to your computer and use it in GitHub Desktop.
Save davidalger/5806612 to your computer and use it in GitHub Desktop.
Strip DEFINER comments from mysqldump. Usage is to pipe mysqldump through this sed command.

Stripping DEFINER from MySQL dumps with sed

LC_ALL=C sed -E 's/DEFINER[ ]*=[ ]*`[^`]+`@`[^`]+`/DEFINER=CURRENT_USER/g'

Typical Usage

pv /path/to/mysqldump.sql.gz \
  | gunzip -c \
  | LC_ALL=C sed -E 's/DEFINER[ ]*=[ ]*`[^`]+`@`[^`]+`/DEFINER=CURRENT_USER/g' \
  | mysql <database>

Occasionally More is Required

pv /path/to/mysqldump.sql.gz \
  | gunzip -c \
  | LC_ALL=C sed -E 's/DEFINER[ ]*=[ ]*`[^`]+`@`[^`]+`/DEFINER=CURRENT_USER/g' \
  | LC_ALL=C sed -E 's/ROW_FORMAT=FIXED//g' \
  | LC_ALL=C sed -E '/\@\@(GLOBAL\.GTID_PURGED|SESSION\.SQL_LOG_BIN)/d' \
  | mysql <database>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment