Skip to content

MySQL 迁移数据库

L edited this page Oct 20, 2021 · 1 revision

思路:创建新数据库,将表逐个搬运到新数据库,再删除旧数据库

create database new_database;
rename table old_database.old_table to new_database.old_table;

为了更方便的找到所有表,写了以下sql

create database new_database;
SELECT CONCAT('rename table old_database.', table_name, '  to new_database.',table_name,';')
FROM information_schema.tables
WHERE table_schema='old_database'
order by table_name;

Clone this wiki locally