The user specified as a definer ('root'@'%') does not exist when using LOCK TABLES
用MySQL的導出語句或備份時的異常
在Linux下:
mysqldump -hlocalhost -uroot -prootdatabasename > /home/myfile/seattle.sql
在Windows下:
mysqldump -hlocalhost -uroot -prootdatabasename> e:/myfile/seattle.sql
出現了如下問題:
mysqldump: Got error: 1449: The user specified as a definer ('root'@'%') does not exist when using LOCK TABLES
分析後發現,是因為存儲過程的建立是seattle使用者定義者,而現在備份的是用root使用者。
還有資料庫在使用狀态,是以導出資料時報錯,不是存儲過程定義者就需要鎖表
--lock-all-tables,-x
在開始導出之前,送出請求鎖定所有資料庫中的所有表,以保證資料的一緻性。
mysqldump: Got error: 1449: The user specified as a definer ('root'@'%') does not exist when using LOCK TABLES這是一個全局讀鎖,并且自動關閉 --single-transaction 和 --lock-tables 選項。
在mysqldump時使用 -x 選項解決此問題。
解決方案有兩種:
第一種:直接加參數
mysqldump -hlocalhost -uroot -proot -x databasename> e:/myfile/seattle.sql
再執行導出就OK
----------------------------------------------------------------------------------------------------------------
第二種:賦予目前導出者seattle所有的權限
隻要給seattle使用者再添加一個對全部host都有可以通路的權限
操作如下:
登陸mysql
mysql -u root -proot
mysql >grant all privileges on *.* to seattle@"%"identified by "123";
mysql >flush privileges;
在cmd執行導出就OK
----------------------------------------------------------------------------------------------------------------
以上問題可以得出,建立存儲過程如果預設參數在備份時有局限性。