1.检查mysql导出配置;
show variables like '%secure%';
2.配置secure_file_priv;如果该项已设置则忽略;
打开mysql配置文件my.ini,加入配置项:secure_file_priv="D:\phpStudy\PHPTutorial\MySQL\outfile"
然后保存,重启mysql服务。
3.封装修改表前缀SQL语句脚本;
SELECT
CONCAT(
'ALTER TABLE ',
table_name,
' RENAME TO newim_',
substring(table_name, 4),
';'
)
FROM
information_schema. TABLES
WHERE
table_name LIKE 'im_%'
INTO OUTFILE 'D:\\phpStudy\\PHPTutorial\\MySQL\\outfile\\alterPref.sql';
4.最后执行sql脚本完成修改操作。
备注:substing函数,截取字符串;用法如下:
substring(str, pos)
substring(str, pos, length)
说明:substring(被截取字段,从第几位开始截取)
substring(被截取字段,从第几位开始截取,截取长度)