记录一次服务器安装mysql,并进行远程连接踩的一些小坑,希望能帮到大家
目录
1、官网下载rpm包
我下载的是mysql8
右键复制下载链接
2、wget下载rpm
wget https://dev.mysql.com/get/mysql80-community-release-el8-4.noarch.rpm
3、下载后yum安装
yum install mysql80-community-release-el8-4.noarch.rpm #安装rpm
yum repolist enabled | grep mysql #检查安装源
yum makecache #生成yum缓存,以免安装错误
yum module disable mysql # 如果提示Unable to find a match: mysql-community-server,禁用本地安装模块
yum install -y mysql-community-server #安装mysql服务
4、启动服务,查看初始密码
systemctl start mysqld #启动mysql
systemctl status mysqld #查看状态
grep 'temporary password' /var/log/mysqld.log #查看初始密码,拿到密码可进行登录和密码修改
#拿到零时密码登陆后更改密码
alter user user() identified by 'password';
5、远程登录
第一次远程连接时会遇到:[HY000][1130]
[HY000][1130] null, message from server: "Host xx.xx.xx.xx' is not allowed to connect to this MySQL server".
如下解决方案:
- 检查服务器是否开放3306端口
- 查看root用户是否有grant_priv 权限,select user ,grant_priv from user (use表数据msyql库);
- 更新root用户可访问host为所有:update user set host='%' where user='root' ;
- 授权任意ip连接:grant all privileges on *.* to 'root'@'%' ;
- 刷新权限flush privileges ;
再次测试,连接成功