1

Is there any way I can export my database from phpMyAdmin 4.9 in a way where the primary and foreign keys are declared in the CREATE TABLE statements ?

CREATE TABLE IF NOT EXISTS Address (
ID int NOT NULL,
country varchar(255) NOT NULL,
street_name varchar(255),
street_number int,
PRIMARY KEY (ID)); 

PhpmyAdmin writes them in a seperate ALTER TABLE statement

CREATE TABLE ...
ALTER TABLE `Address`ADD PRIMARY KEY (`ID`);

I went through the custom exportation but I did not find such an option, or maybe I missed it.

joe1531
  • 345
  • 4
  • 16
  • https://stackoverflow.com/a/11407415/15160601 – zoldxk Apr 17 '21 at 23:42
  • why it is necessary? for the sql it doesn't matter – nbk Apr 18 '21 at 00:10
  • the thing is I am running the sql script for an entrypoint for a docker database container that has mulitple databases for microservices, I don't want errors for duplicate primary_keys ( mysql 1068 error ) to take place everytime someone restarts the database container. The database and tables creation is well handled by the statements ( CREATE TABLE, DATABASE IF EXISTS ) and also the data insertion ( INSERT IGNORE INTO ) but the ALTER TABLE is a problem, the ALTER IGNORE TABLE does not work anymore since MySQL 4 I think so i found myself stuck. – joe1531 Apr 18 '21 at 00:16

1 Answers1

0

I found a solution using mysqldump with the option --single-transaction This way, the PRIMARY KEYS and FOREIGN KEYS are added in the table creation statements.

joe1531
  • 345
  • 4
  • 16