CenterOS7安装mysql8.0
2021-03-27 本文已影响0人
澹台琉璃
1.先删除之前安装的mysql
通过 rpm -qa | grep mariadb
和rpm -qa | grep mysql
命令查看 mariadb 和mysql 的安装包
rpm -e 包名
删除所有的安装包
2.从官网获取下载链接
如图选择版本, 点击Download
image.png
右键点击No thanks, 复制链接
image.png
3. 下载mysql安装包
1.创建mysql目录 mkdir /usr/local/mysql
2.进入刚才创建的目录cd /usr/local/mysql
3.下载文件 wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.23-1.el7.x86_64.rpm-bundle.tar
4.安装mysql
-
tar -xvf mysql-8.0.23-1.el7.x86_64.rpm-bundle.tar
解压tar包
2.安装common, libs, client, server
rpm -ivh mysql-community-common-8.0.23-1.el7.x86_64.rpm --nodeps --force
rpm -ivh mysql-community-libs-8.0.23-1.el7.x86_64.rpm --nodeps --force
rpm -ivh mysql-community-client-8.0.23-1.el7.x86_64.rpm --nodeps --force
rpm -ivh mysql-community-server-8.0.23-1.el7.x86_64.rpm --nodeps --force
3.查看刚才安装的包rpm -qa | grep mysql
image.png
4.初始化数据库相关配置
mysqld --initialize
chown mysql:mysql /var/lib/mysql -R
systemctl start mysqld.service
systemctl enable mysqld
5.查看随机生成的密码cat /var/log/mysqld.log | grep password
image.png
6.修改密码
mysql -uroot -p
进入数据库, 输入刚才看到的密码
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '密码';
修改密码
exit
退出mysql, 使用新密码重新登录
7. 设置数据库允许远程连接
mysql -u root -p
use mysql;
select host, user, authentication_string, plugin from user;
// 允许远程主机连接
update mysql.user set host='%' where user='root';
// 修改加密方式
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123456';
// 刷新权限
FLUSH PRIVILEGES;
// 开启系统防火墙
firewall-cmd --zone=public --add-port=3306/tcp --permanent
firewall-cmd --reload
// 配置文件解决sql_mode 'only_full_group_by' 报错
[mysqld]
user=mysql
default-storage-engine=INNODB
character-set-server=utf8
default_authentication_plugin=mysql_native_password
sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION'
[client]
default-character-set=utf8
[mysql]
default-character-set=utf8