Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 80 You must be signed in to star a gist
  • Fork 9 You must be signed in to fork a gist
  • Save iamphilrae/d538d5b48608de290bfee791df3e6f54 to your computer and use it in GitHub Desktop.
Save iamphilrae/d538d5b48608de290bfee791df3e6f54 to your computer and use it in GitHub Desktop.
phpMyAdmin Export Filename Template, Including Date and Time
@SuporteWebGerente
Copy link

Very useful, thanks for sharing!

@dennorske
Copy link

Very useful, indeed. Thanks 👍

@Leo240
Copy link

Leo240 commented Jan 22, 2018

Thank you!

@javyyk
Copy link

javyyk commented Feb 16, 2018

Thanks!

@diereysaa
Copy link

Great tip Thanks!

@mddanishansari
Copy link

How do I do it like this?
Database name: test
"test-backup-2018-07-14.sql"

@MaxwellRU
Copy link

@mddanishansari

How do I do it like this?
Database name: test
"test-backup-2018-07-14.sql"

@DATABASE@-backup-%Y-%m-%d

@stianandreassen
Copy link

Thanks!

@japo32
Copy link

japo32 commented Jan 3, 2019

The gift that keeps on giving. Thanks mate!

@jimmyadaro
Copy link

jimmyadaro commented Apr 25, 2019

In case you haven't created an export template before, you should do this:

Go to "PHPMyAdmin", select your database, click "Export" on the top menu, enter a name for your template (whatever, you should understand it), click "Custom" under "Export method", scroll down a little bit to reach the "File name template" section, and then enter your template name (like @DATABASE@__%Y-%m-%d_%H-%M-%S). Then scroll up and click "Create" button (next to the "New template" text input).

That's it.

@LFavier
Copy link

LFavier commented Oct 23, 2019

Thanks, exactly was I was looking for.

@zrubinrattet
Copy link

the amount of times I keep revisiting this snippet amazes me. thanks!!

@MeiRct
Copy link

MeiRct commented Oct 28, 2020

Does anyone know if it's possible to include a space character in the exported filename?

@iamphilrae
Copy link
Author

@MeiRct

Does anyone know if it's possible to include a space character in the exported filename?

Yeah that's no problem at all, just set the format to include the spaces, e.g.

@DATABASE@ %Y-%m-%d %H-%M-%S

This should output a filename of the format:

my-database-name 2020-10-28 17-01-00.sql

@mateosantosdev
Copy link

Thanks!

@andrekutianski
Copy link

Thanks!

@hbend1li
Copy link

Thanks!

@YouveGotMeowxy
Copy link

Does anyone know why the @DATABASE@ variable would be empty when doing an export?

@SERVER@ @DATABASE@__%Y-%m-%d_%H-%M-%S

results in:

mysql_3306___2022-10-30_02-00-13.sql.gz

@iamphilrae
Copy link
Author

Does anyone know why the @DATABASE@ variable would be empty when doing an export?

@SERVER@ @DATABASE@__%Y-%m-%d_%H-%M-%S

results in:

mysql_3306___2022-10-30_02-00-13.sql.gz

You could give __DB__ a try. I believe it's a legacy variable, and should output the same value as @DATABASE@, however you never know, may work.

@YouveGotMeowxy
Copy link

@iamphilrae Thank you. I just gave it a shot, but unfortunately still no luck. :/

@JorgenBB
Copy link

According to phpMyAdmin FAQ, @database@ refers to "the currently open database.
But since you are not "in" a database, it is not available.
Doesn't even work when you choose to export each database into its own file.
Weird, but that is phpMyAdmin's choice.

@YouveGotMeowxy
Copy link

@JorgenBB Ahhhh, ok, that makes some sense, thank you.

It definitely is a strange decision, or perhaps just an oversight if they've never come across the issue themselves? It seems like a pretty easy thing to add, just getting the name of the db as it iterates through the list, and add it to a variable. I'm not much of a coder or I'd try submitting a PR myself. :/

@phpmyadmin team, please add this 'enhancement', I beeeegg you! QOL improvement to the n'th degree! :)

@williamdes
Copy link

@we684123
Copy link

we684123 commented Dec 9, 2022

Thanks! ヾ(≧▽≦*)o

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment