1. 程式人生 > 其它 >建立Mysql使用者並授權

建立Mysql使用者並授權

  • mysql檢視當前登入使用者,當前資料庫:
    select user(); -- 這個一般會帶出ip
    select current_user(); -- 這個查出的是定義的使用者 select database();
  • 修改root或其他使用者密碼
    update mysql.user set password=password('new_pass') where user='user_name';
  •  建立新使用者並授權
    /* all privileges  所有許可權  
      *.* 所有資料庫 所有表
      
    fine_report'@'%' 表示 登入名稱是 fine_report %表示許可權級別 可以用
    %192.168.2.%
    */
    grant all privileges on *.* to 'fine_report'@'%' identified by '使用者密碼' WITH GRANT OPTION; -- select 表示只有查詢許可權 grant select on *.* to 'fine_report'@'%' identified by '使用者密碼' WITH GRANT OPTION;
    如果此時報下面問題 表示程式碼不符合規則
     [Code: 1819, SQL State: HY000]  Your password does not satisfy the current policy requirementsc

    -- 查詢密碼規則
    SHOW VARIABLES LIKE 'validate_password%';

    可以設定許可權為最低然後在修改

    set global validate_password_policy=LOW;

  設定成功後(只有查詢許可權 select_priv)查詢許可權

 

show grants for 'fine_report'@'%'