mysql設置遠程訪問 包括操作用戶

查看數據庫密碼設置限制
SHOW VARIABLES LIKE 'validate_password%';

修改爲最低限制
set global validate_password.policy=LOW;

修改長度爲6位
set global validate_password.length=6;

創建用戶
create user 'root'@'%' identified with mysql_native_password by 'password';

修改用戶密碼(任意)
alter user 'root'@'localhost' identified by "password";
alter user 'root'@'localhost' identified with mysql_native_password by "root";
alter user 'root'@'localhost' identified with caching_sha2_password by "root";
(MySQL8默認的認證插件是caching_sha2_password,
很多客戶端都不支持,可將默認的認證插件修改爲mysql_native_password,
在配置文件中配置default_authentication_plugin=mysql_native_password。)

修改用戶host
update mysql.user set host = 'localhost' where user = 'root';

刪除用戶
drop user 'root'@'%';

設置權限
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION;

刷新
FLUSH PRIVILEGES;

//一般上面的用不到 我用來做記錄 只需要將root的host修改爲%在設置權限就好

修改root用戶host爲%(表示所有IP都可訪問)
update mysql.user set host = '%' where user = 'root';

設置權限
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION;

刷新
FLUSH PRIVILEGES;

不懂可留言
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章