为了远程连接,您必须在/etc/mysql/mysql. d/mysqld.cnf中让MySQL绑定端口:3306连接到您的机器IP,然后您必须在localhost和'%'通配符中创建用户,并授予所有DB的权限。见下文:
用你的IP地址替换xxx(通常0.0.0.0)
bind-address= xxx.xxx.xxx.xxx
然后
CREATE USER 'myuser'@'localhost' IDENTIFIED BY 'mypass';
CREATE USER 'myuser'@'%' IDENTIFIED BY 'mypass';
再然后
GRANT ALL ON *.* TO 'myuser'@'localhost';
GRANT ALL ON *.* TO 'myuser'@'%';
取决于你的操作系统,你可能还需要打开3306端口的远程访问权限。
最后重启MYSQL:
sudo systemctl restart mysql