Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove "CREATE DATABASE IF NOT EXISTS" statement from Export in phpMyAdmin 4?

I'm using phpMyAdmin 4.0.2 and seems when doing an export over a whole DB, by default it adds the statement "CREATE DATABASE IF NOT EXISTS" in the beginning of the export SQL.

I wasn't able to find a config option or any option to disable that... So is there a way to disable that and not have that statement in my exports by default?

like image 641
Vlad Avatar asked Jun 03 '13 08:06

Vlad


People also ask

Which clause is used to create a database only if it doesn't already exist?

6. To create a database only if it doesn't already exist, which clause is used? Explanation: The 'CREATE DATABASE' statement supports many optional values. To create a database named 'my_db' only if it doesn't already exist, we write 'CREATE DATABASE IF NOT EXISTS my_db'.

Why would we choose to Export a specific table from a phpMyAdmin database?

Exporting databases and tables through PhpMyAdmin can help with making backups, transferring data to another server, making reports, or even with creating a file that can be imported into another application.


1 Answers

This behavior did not happen by default in version 3. A quick fix, actually a hack and thus not the desirable solution, is to edit the export class file located in libraries/plugins/export/ExportSql.class.php and force the CREATE and USE statements to be commented out by adding "-- " before them, as such: Line 709

$create_query = '-- CREATE DATABASE IF NOT EXISTS '

Line 734

'-- USE ' . PMA_Util::backquoteCompat($db, $compat)

Edit: There's a drawback, and that is if you export one or more entire databases (not just some or all the tables inside a database), then the CREATE and USE statements appear commented also.

like image 108
Hermes Avatar answered Oct 05 '22 22:10

Hermes