MySQL資料庫下使用者及使用者權限配置

來源:互聯網
上載者:User

MySQL資料庫下使用者及使用者權限配置

問題:使用某大神寫的遠程工具管理MySQL資料庫時發現所有資料能正常顯示,但是無法進行刪除、修改等操作。

思路:可以遠程讀取到資料庫裡的資訊,說明當前主機可以遠端連線資料庫。卻無法進行刪除、修改這些操作,說明某些許可權並未賦予當前遠端使用者。

解決方案:

查看目前使用者許可權

1 > show grants for username

  顯示目前使用者下的許可權為:select,insert,update,delete

12 GRANT USAGE ON *.* TO 'username'@'host' IDENTIFIED BY PASSWORD '*BB318072E265C419B3E1E19A4DAD1FA969B9B4D4' //只可以在本地登陸的 不能操作的使用者GRANT SELECT, INSERT, UPDATE, DELETE ON `dbName`.* TO 'usename'@'host'                                    //此使用者擁有select/insert/update/delelte許可權

    這樣看來,應該是具備刪除、修改這些許可權的,可是在遠程工具上卻不能進行操作。

  仔細排查後,發現大腿寫的這個工具對資料庫的操作基本上都是通過函數執行的,我這個使用者的許可權裡並未賦予預存程序、儲存函數的相關許可權,當然就不能進行相關操作了

  於是,給使用者添加預存程序及儲存函數許可權

1 GRANT DELETE, INDEX, EXECUTE, CREATE ROUTINE, ALTER ROUTINE ON `dbName`.* TO 'username'@'host'

  查看使用者權限為

?
12 GRANT USAGE ON *.* TO 'username'@'host' IDENTIFIED BY PASSWORD '*938D2D224D12DAD427AB953B931EA6DF0CF0656A'GRANT SELECT, INSERT, UPDATE, DELETE, INDEX, EXECUTE, CREATE ROUTINE, ALTER ROUTINE ON `dbName`.* TO 'username'@'host'

    再使用遠程工具,可正確使用

-----------------------------------------------------------------------------------------------------

  附:匯入資料庫自訂函數

?
1 mysqldump -uroot -ntd -R dbName > dbName.sql

  發現匯入出現錯誤資訊

?
1 ERROR 1418 (HY000): 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)

  錯誤資訊1481,當匯入自訂函數時相當於建立自訂函數到資料庫中,但是因為有一個安全參數沒有開啟,log_bin_trust_function_creators 預設為0(即OFF),

      是不允許function的同步的(也就是說不允許建立函數),開啟這個參數,就可以建立成功了。

  查看log_bin_trust_function_creators值

123456 > show variables like "%func%"--------------------------------------|Variable_name                  |Value|--------------------------------|----- |log_bin_trust_function_creators| OFF |--------------------------------------

  value為OFF,說明是不允許建立函數,修改這個值,即可

12345678 > set global log_bin_trust_function_creators=1; >show variables like "%func%"--------------------------------------|Variable_name                  |Value|--------------------------------|----- |log_bin_trust_function_creators| ON |--------------------------------------

  注意:匯入完成後記得把值設回0(即OFF),具體原因就不細說了。

本文永久更新連結地址:

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.