mysqldump 5.7->8.0

备份shell命令:

‘mysqldump --column-statistics=0 --set-gtid-purged=OFF ' \
              '-h{
    
    ip} -u{
    
    user} -p{
    
    passwd} {
    
    parameter} --add-drop-database --databases {
    
    database} > {
    
    backup_path}/{
    
    database}_{
    
    date}.sql’

-set-gtid-purged=off 这个参数防止报gtid错误,因为mysql5.6之后增加了gtid这个特性 这个是关掉这个特性的意思
–column-statistics=0  因为新版的mysqldump默认启用了一个新标志,通过- -column-statistics=0来禁用他
-R 备份存储过程和函数 (不加此参数只会备份databases 的基础表和视图)

数据还原:

①ERROR 1231 (42000) at line 1125: Variable ‘sql_mode’ can’t be set to the value of ‘NO_AUTO_CREATE_USER’

sed -i 's/,NO_AUTO_CREATE_USER//g' ./database_2023-06-21.sql

②ERROR 1418 (HY000) at line 3445: This function has none of DETERMINISTIC, NO SQL, or READS SQL DATA in its declaration and binary logging is enabled (you might want to use the less safe log_bin_trust_function_creators variable)
备份时备份了函数,mysql8.0开启了binlog,我们就必须为我们的function指定一个参数(log_bin_trust_function_creators )。参考来源:https://zhuanlan.zhihu.com/p/370169125

show variables like 'log_bin_trust_function_creators';
SET GLOBAL log_bin_trust_function_creators = 1;

猜你喜欢

转载自blog.csdn.net/keepandkeep/article/details/131328083