Mysql will change from MyISAM to INNODB

Today update table field in django, since mysql upgrade from 5.1 to 5.7. Former foreign key must be changed for the new INNODB can continue from MYISAM.

Process is a bit exciting, but okay, as long as the process to think clearly, make a backup in advance, it lacks big problem.

A, django in the mysql configuration:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'PDB',
        'USER': 'user',
        'PASSWORD': 'xxxx',
        'HOST': '1.2.3.4',
        'PORT': '3306',
        'OPTIONS': {"init_command": "SET default_storage_engine=INNODB;"},
    },
}

Second, see table storage engine is now Curry

SELECT table_name, table_type, engine FROM information_schema.tables 
WHERE table_schema = 'xxxxDB' ORDER BY table_name DESC;

Third, the data table to generate change all engines mysql statement

SELECT CONCAT( 'ALTER TABLE ', TABLE_NAME, ' ENGINE=InnoDB;' )
FROM information_schema.tables
WHERE table_schema = 'xxxxDB';

Fourth, these statements into mysql in the implementation of a

...
ALTER TABLE A ENGINE=InnoDB;                                
ALTER TABLE B ENGINE=InnoDB;                                  
ALTER TABLE C ENGINE=InnoDB;                                 
ALTER TABLE H ENGINE=InnoDB;                                
ALTER TABLE D ENGINE=InnoDB;                                  
ALTER TABLE E ENGINE=InnoDB;
...

Fifth, in the my.cnf in the default engine to innodb, then use the show engine, you can see the mysql default storage engine.

show engine

 Six Once you have the above operation, makemigrations, migrate command django, the question on nothing. If the above steps did the operation go wrong, remember to restore the database, and then operate.

Guess you like

Origin www.cnblogs.com/aguncn/p/11084088.html