centos7 Mysql5.8极简安装,解决远程无法连接问题和mysql 1251问题

时间:2022-06-07 17:22:17

1.1centos7下mysql最简单的安装模式

官方文档

  1. Download MySQL Yum Repository(http://dev.mysql.com/downloads/repo/yum/)
# 下载
wget https://dev.mysql.com/get/mysql80-community-release-el7-1.noarch.rpm
# 本地安装
yum localinstall mysql80-community-release-el7-1.noarch.rpm -y
# 查看yum repository是否安装成功
yum repolist enabled | grep "mysql.*-community.*"
# 下载mysql server
yum install mysql-community-server
# 启动mysql
systemctl start mysqld
# 查看mysql状态
systemctl status mysqld
# 查看临时生成的密码,会显示临时密码,可以使用临时密码登录,然后修改
grep 'temporary password' /var/log/mysqld.log
# 登录mysql
mysql -uroot -p
 Enter password:
  1. 修改用户密码
# 修改密码
ALTER USER 'root'@'localhost' IDENTIFIED BY 'HelloJava0903!';
mysql -uroot -pHelloJava0903!
  1. 解决mysql5.8无法远程连接的问题
use mysql;
select host,user from user where user='root'; # 查看host,正常情况,host=localhost
update user set host='%' where user='root'; #更改host为所有ip
select host,user from user where user='root'; # 查看更改,此时 host=%

mysql8问题描述

Error: 1251

Message: Client does not support authentication protocol requested by server; consider upgrading MySQL client

解决方法

USE mysql;
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '你的数据库密码';
FLUSH PRIVILEGES;