1 在控制台执行
mysql -uroot -p
系统提示输入数据库root用户的密码,输入完成后即进入mysql控制台
2 选择数据库
mysql -uroot -p
use mysql;
开启远程连接
root 用户名
% 所有人都可以访问
password 密码
GRANT ALL PRIVILEGES ON . TO 'root'@'%' IDENTIFIED BY 'your password' WITH GRANT OPTION;
FLUSH PRIVILEGES;
3 重起mysql服务
service mysqld restart
如果执行完以上步骤,还是不能远程连接,那么我们需要查看服务器的防火墙是否开启
service iptables status centos7 systemctl status firewalld
如果防火墙开启,请关闭
service iptables stop centos7 systemctl stop firewalld
到此就可以远程连接了!
请注意一个坑,在设置完权限,且刷新了权限,且重启了mysql后navicat还是连接不上。请考虑
发现防火墙也会拦截tomcat下项目的数据库连接,即使连接是localhost
我们需要查看服务器的防火墙是否开启
service iptables status centos7 systemctl status firewalld
如果防火墙开启,请关闭
service iptables stop centos7 systemctl stop firewalld
到此就可以远程连接了!
Linux安装mysql时出现:启动后停止mysql,出现Redirecting to /bin/systemctl restart mysql.service解决方式
直接使用如下命令即可:
使用如下命令操作mysql:
systemctl restart mysqld.service
systemctl start mysqld.service
systemctl stop mysqld.service