#4019 (ok 4.0.5) Create database if not exists (export)

4.0.4
fixed
None
1
2014-06-24
2013-07-14
aommundsen
No

After upgrading from phpMyAdmin 3.5.8.1 to 4.0.4.1, there is a difference in the .sql file created when doing "Export" that causes trouble for us offering shared hosting.

In phpMyAdmin 4.0.4.1 the following is added in the .sql file after doing "Export" (I have replaced database user and name with "user_name"):

CREATE DATABASE IF NOT EXISTS user_name DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci;
USE user_name;

The above two lines was not added to the .sql file when doing "Export" in phpMyAdmin 3.5.8.1, only when upgrading to 4.0.4.1, those lines are added in the .sql file.

Please note that we offer shared hosting, and the customers create databases in a different control panel, not in phpMyAdmin itself. The customers can have several databases under same database user.

When the customer to a "Export" in phpMyAdmin of a existing database, and then create a new database, and then use "Import" in phpMyAdmin to import the .sql file into the new database, they get a error because of those lines and phpMyAdmin is trying to create a new database or if the database still exist, phpMyAdmin try to import it to the old database, wich is wrong because the customer is trying to import it to a new database.

Then we get support tickets, and must explain to the customer that they first need to manually edit the .sql file and remove these lines:

CREATE DATABASE IF NOT EXISTS user_name DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci;
USE user_name;

Then after removing those, they can do a import to the new database the have created.

I don't know if it was intentionally that you added those two lines in phpMyAdmin 4.0.x or not, but it causes trouble for our customers. Also I do not see what the benefit of having those lines in the .sql file would be.

So please please don't add those two lines when doing export? I hope you can change this in future version? Thanks!

Discussion

  • Marc Delisle

    Marc Delisle - 2013-07-14

    See also https://sourceforge.net/p/phpmyadmin/feature-requests/1438/.

    Meanwhile, you can remove this behavior with the following temporary patch:
    diff --git a/export.php b/export.php
    index c2373e3..4c9c331 100644
    --- a/export.php
    +++ b/export.php
    @@ -721,10 +721,6 @@ do {
    if (! $export_plugin->exportDBHeader($db)) {
    break;
    }
    - if (! $export_plugin->exportDBCreate($db)) {
    - break;
    - }
    -
    if (method_exists($export_plugin, 'exportRoutines')
    && strpos($GLOBALS['sql_structure_or_data'], 'structure') !== false
    && isset($GLOBALS['sql_procedure_function'])

     
  • aommundsen

    aommundsen - 2013-07-14

    Thank you for the patch! I have voted in the feature request you linked to. However, my personal opinion on this, is to remove it as default. If not, a config parameter would of course be enough for me.

     
  • Marc Delisle

    Marc Delisle - 2013-07-19
    • assigned_to: Marc Delisle
     
  • Marc Delisle

    Marc Delisle - 2013-07-19
    • summary: Create database if not exists (export) --> (ok 4.0.5) Create database if not exists (export)
    • status: open --> resolved
    • Priority: 5 --> 1
     
  • Marc Delisle

    Marc Delisle - 2013-08-04
    • Status: resolved --> fixed
     
  • Isaac Bennetch

    Isaac Bennetch - 2014-06-24

    Note that this behavior can cause difficulty when doing an export of several databases if the user doesn't select the CREATE DATABASES... checkbox. In this case, the user can add $cfg['Export']['sql_create_database'] = true; to their config.inc.php.

     

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks