導出函數、存儲過程
- mysqldump -u root -p -n -t -d -R 數據庫名 > 文件名
其中,-d 表示--no-create-db, -n表示--no-data, -t表示--no-create-info, -R表示導出function和procedure。
所以上述代碼表示僅僅導出函數和存儲過程,不導出表結構和數據。但是,這樣導出的內容里,包含了 trigger。再往mysql中導入時就會出問題,錯誤如下:
ERROR 1235 (42000) at line **: This version of MySQL doesn't yet support ‘multiple triggers with the same action time and event for one table’
所以在導出時需要把trigger關閉。代碼為
- mysqldump -u root -p -n -t -d -R --triggers=false 數據庫名 > 文件名
這樣導入時,會出現新的問題:
ErrorCode:1418
This function has none of DETERMINISTIC, NOSQL, or READS SQL DATA inits declaration and binary logging is enabled (you might want to use the less safe log_bin_trust_function_creators variable)
- 解決方法一
在/etc/my.cnf中找到[mysqld],在它下面添加這樣一行(需重啟mysql):
log-bin-trust-function-creators=1
-
解決方法二
命令行執行:
set global log_bin_trust_function_creators=1; -
導入語句:
mysql -uroot -p 數據庫 < 導出的.sql文件
或在命令行執行
use 數據庫名
source /root/導出的.sql文件
————————————————
參考文章來源