用root身份登錄mysql服務器
mysql -h localhost -u root
賦予任何主機使用 username 遠程訪問
mysql>GRANT ALL PRIVILEGES ON *.* TO 'username'@'%'WITH GRANT OPTION
設置指定的用戶只能從指定的ip進行訪問,這裡是新建了遠程訪問的用戶
GRANT ALL PRIVILEGES ON *.* TO 'user'@'192.168.1.250' IDENTIFIED BY 'password' WITH GRANT OPTION;
指定已有用戶只能從指定ip訪問
GRANT ALL PRIVILEGES ON *.* TO 'user'@'192.168.1.250' WITH GRANT OPTION;
刷新生效
FLUSH PRIVILEGES