Rewriting a database name

Suppose you want to restore the binary log of the employees database on a production server as employees_dev on a development server. You can use the --rewrite-db='from_name->to_name' option. This will rewrite all occurrences of from_name to to_name.

To convert multiple databases, specify the option multiple times:

shell> sudo mysqlbinlog /data/mysql/binlogs/server1.000001 --start-position=1499 --stop-position=1646 --rewrite-db='employees->employees_dev'~# at 1499#170815 13:29:27 server id 200  end_log_pos 1646 CRC32 0xc73d68fb     Query    thread_id=8    exec_time=0    error_code=0use `employees_dev`/*!*/;~~UPDATE salaries SET salary=salary*2 WHERE emp_no<10002/*!*/;SET @@SESSION.GTID_NEXT= 'AUTOMATIC' /* added by mysqlbinlog ...

Get MySQL 8 Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.