如何批量修改mysql的表前缀名称
2个回答
展开全部
方法/步骤
命令行登陆MySQL,进入相应的数据库,本例是shopping(注:用其他工具也可以,比如Navicat for MySQL)。
输入查询表语句查看有哪些表:
select table_name FROM information_schema.tables;
查询结果有许多表,以shopping开头的是我自己建立的,其他的是数据库系统自己建立的。
输入下面语句,查询以shopping开头的数据表:
select table_name FROM information_schema.tables where table_name like 'shopping_%';
输入下面语句:
Select CONCAT( 'ALTER TABLE ', table_name, ' RENAME TO buy_', substring(table_name,9 ),';' )FROM information_schema.tablesWhere table_name LIKE 'shopping_%';
注意:9表示从“shopping_”后面开始
拷贝出以alter开头的所有语句,用Navicat for MySQL工具更直观。
ALTER TABLE shopping__admin RENAME TO buy___admin;ALTER TABLE shopping__adminlog RENAME TO buy___adminlog;ALTER TABLE shopping__article RENAME TO buy___article;ALTER TABLE shopping__basket RENAME TO buy___basket;ALTER TABLE shopping__book RENAME TO buy___book;ALTER TABLE shopping__comment RENAME TO buy___comment;ALTER TABLE shopping__gb RENAME TO buy___gb;ALTER TABLE shopping__gou RENAME TO buy___gou;ALTER TABLE shopping__huo RENAME TO buy___huo;ALTER TABLE shopping__hw RENAME TO buy___hw;ALTER TABLE shopping__logo RENAME TO buy___logo;ALTER TABLE shopping__newsnsort RENAME TO buy___newsnsort;ALTER TABLE shopping__newssort RENAME TO buy___newssort;ALTER TABLE shopping__nsort RENAME TO buy___nsort;ALTER TABLE shopping__pay RENAME TO buy___pay;ALTER TABLE shopping__payonline RENAME TO buy___payonline;ALTER TABLE shopping__pinpai RENAME TO buy___pinpai;ALTER TABLE shopping__ps RENAME TO buy___ps;ALTER TABLE shopping__pub RENAME TO buy___pub;ALTER TABLE shopping__quan RENAME TO buy___quan;ALTER TABLE shopping__rep RENAME TO buy___rep;ALTER TABLE shopping__rule RENAME TO buy___rule;ALTER TABLE shopping__search RENAME TO buy___search;ALTER TABLE shopping__sort RENAME TO buy___sort;ALTER TABLE shopping__sub RENAME TO buy___sub;ALTER TABLE shopping__system RENAME TO buy___system;ALTER TABLE shopping__totime RENAME TO buy___totime;ALTER TABLE shopping__type RENAME TO buy___type;ALTER TABLE shopping__user RENAME TO buy___user;ALTER TABLE shopping__usertype RENAME TO buy___usertype;ALTER TABLE shopping__wrzcnet_ad RENAME TO buy___wrzcnet_ad;ALTER TABLE shopping__wrzcnet_link RENAME TO buy___wrzcnet_link;ALTER TABLE shopping__zp RENAME TO buy___zp;
运行拷贝的语句:
执行完后,在用上面的查询语句查询一下:
select table_name FROM information_schema.tables where table_name like 'shopping_%';
发现没有数据,说明修改成功;修改查询语句:
select table_name FROM information_schema.tables where table_name like 'buy_%';
命令行登陆MySQL,进入相应的数据库,本例是shopping(注:用其他工具也可以,比如Navicat for MySQL)。
输入查询表语句查看有哪些表:
select table_name FROM information_schema.tables;
查询结果有许多表,以shopping开头的是我自己建立的,其他的是数据库系统自己建立的。
输入下面语句,查询以shopping开头的数据表:
select table_name FROM information_schema.tables where table_name like 'shopping_%';
输入下面语句:
Select CONCAT( 'ALTER TABLE ', table_name, ' RENAME TO buy_', substring(table_name,9 ),';' )FROM information_schema.tablesWhere table_name LIKE 'shopping_%';
注意:9表示从“shopping_”后面开始
拷贝出以alter开头的所有语句,用Navicat for MySQL工具更直观。
ALTER TABLE shopping__admin RENAME TO buy___admin;ALTER TABLE shopping__adminlog RENAME TO buy___adminlog;ALTER TABLE shopping__article RENAME TO buy___article;ALTER TABLE shopping__basket RENAME TO buy___basket;ALTER TABLE shopping__book RENAME TO buy___book;ALTER TABLE shopping__comment RENAME TO buy___comment;ALTER TABLE shopping__gb RENAME TO buy___gb;ALTER TABLE shopping__gou RENAME TO buy___gou;ALTER TABLE shopping__huo RENAME TO buy___huo;ALTER TABLE shopping__hw RENAME TO buy___hw;ALTER TABLE shopping__logo RENAME TO buy___logo;ALTER TABLE shopping__newsnsort RENAME TO buy___newsnsort;ALTER TABLE shopping__newssort RENAME TO buy___newssort;ALTER TABLE shopping__nsort RENAME TO buy___nsort;ALTER TABLE shopping__pay RENAME TO buy___pay;ALTER TABLE shopping__payonline RENAME TO buy___payonline;ALTER TABLE shopping__pinpai RENAME TO buy___pinpai;ALTER TABLE shopping__ps RENAME TO buy___ps;ALTER TABLE shopping__pub RENAME TO buy___pub;ALTER TABLE shopping__quan RENAME TO buy___quan;ALTER TABLE shopping__rep RENAME TO buy___rep;ALTER TABLE shopping__rule RENAME TO buy___rule;ALTER TABLE shopping__search RENAME TO buy___search;ALTER TABLE shopping__sort RENAME TO buy___sort;ALTER TABLE shopping__sub RENAME TO buy___sub;ALTER TABLE shopping__system RENAME TO buy___system;ALTER TABLE shopping__totime RENAME TO buy___totime;ALTER TABLE shopping__type RENAME TO buy___type;ALTER TABLE shopping__user RENAME TO buy___user;ALTER TABLE shopping__usertype RENAME TO buy___usertype;ALTER TABLE shopping__wrzcnet_ad RENAME TO buy___wrzcnet_ad;ALTER TABLE shopping__wrzcnet_link RENAME TO buy___wrzcnet_link;ALTER TABLE shopping__zp RENAME TO buy___zp;
运行拷贝的语句:
执行完后,在用上面的查询语句查询一下:
select table_name FROM information_schema.tables where table_name like 'shopping_%';
发现没有数据,说明修改成功;修改查询语句:
select table_name FROM information_schema.tables where table_name like 'buy_%';
2019-01-21
展开全部
dedecms织梦安装时,默认数据库表前缀是dede_,如果你用的是虚拟主机只有一个数据库,同时用dedecms程序建立多个网站时(如站内站,几个网站用同一数据库)就用要更改数据库前缀了。这是mysql数据库表前缀批量替换修改方法www.lmlblog.com/331.html,希望能帮到你。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |