4

When I export a MySQL database with Adminer or with mysqldump, it produces a .sql file with each table definition followed by (if the table is non-empty) an INSERT statement (or multiple statements for large tables). The table definition includes indexes and constraints. It will also include the AUTO_INCREMENT value if that is different from what you'd get after running the inserts.

By contrast, a PhpMyAdmin export defines the table without any indexes or constraints, and then inserts the data. At the end, after all tables have been created and all data has been inserted, are a bunch of ALTER TABLE commands to add keys, then a further set to add AUTO_INCREMENT rules, and finally a further set to add constraints.

Why the difference? Both export styles will produce the same database in the end. I assume that PhpMyAdmin made a deliberate, intentional choice to deviate from the mysqldump style. In my subjective experience (I've not actually measured) PhpMyAdmin dumps are slower to run than Adminer or mysqldump dumps. I imagine that they must have some benefit. What?

I might guess that if you're running a PhpMyAdmin dump on an older version of MySQL which doesn't understand constraints (do any such exist?) you will at least have all your data before hitting an error. Perhaps in this sense the PhpMyAdmin dumps are more robust?

7
  • 3
    CREATE+INSERT+INDEX is more fast then CREATE+INDEX+INSERT.
    – Akina
    Commented Nov 25, 2019 at 17:44
  • So that means that my subjective impression is wrong?
    – TRiG
    Commented Nov 25, 2019 at 18:55
  • Dropping indexes before doing batch inserts is a frequently used strategy to speed up bulk inserts. This is just an example of that. Why don't you do a test on your system and see how it works out for you?
    – Vérace
    Commented Nov 26, 2019 at 0:40
  • @Akina - That does not apply to the PRIMARY KEY and AUTO_INCREMENT, especially when the data to insert is in PK order. CREATE+PRIMARYKEY+INSERT+INDEX may be the best in most cases
    – Rick James
    Commented Nov 27, 2019 at 5:54
  • @RickJames PRIMARY KEY must be created in CREATE TABLE.
    – Akina
    Commented May 25, 2022 at 16:53

1 Answer 1

-3

It's possible to modify PHPMYADMIN to put the PRIMARY KEY and attributes directly into the CREATE TABLE structure. In this example, I'll explain how to do it using a WAMP server.

We want to edit the following file, and make two changes:

C:\Networking\wamp64\apps\phpmyadmin5.0.2\libraries\classes\Plugins \Export\ExportSql.php
  1. On line 1822 I commented out:

    // $ create_query = $ statement-> build ();
    
  2. On line 1720 I commented out:

    $ alter_header = 'ALTER TABLE' at line 1822 end statement}
    

Afterwards I tried export and it works with PRIMARY KEY and attributes placed in CREATE TABLE structure.

3
  • It seems the authors did this for the speed of execution, however for large data if you don't use -transaction- and -rollback-, imports and exports can be a timeout problem. It may not be best practice to change the code, but it works and is useful.
    – Meggis
    Commented Oct 19, 2022 at 17:58
  • I'm mostly asking why PhpMyAdmin does what it does, not really asking how to change it.
    – TRiG
    Commented Jun 14, 2023 at 16:25
  • I'm curious to know if this actually works (As of this writing, the reason this has a score of -3 is more likely because of the poor english, but now that it's been edited to be more readable, I'd be interested to know if this actually does anything.) Commented Aug 21, 2023 at 10:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.