Linux(CentOS 7)下安装 MySQL 8.0.31

一、下载

https://dev.mysql.com/downloads/mysql/  注意,由于是Centos 7 ,就下载Linux 7  

Linux(CentOS 7)下安装 MySQL 8.0.31_第1张图片

Linux(CentOS 7)下安装 MySQL 8.0.31_第2张图片 

二、部署

[root@jerry src]# ll
-rw-r--r--. 1 root root 906106880 1月   3 15:44 mysql-8.0.31-1.el7.x86_64.rpm-bundle.tar

[root@jerry src]# tar -xvf mysql-8.0.31-1.el7.x86_64.rpm-bundle.tar
[root@jerry src]# ls
mysql-8.0.31-1.el7.x86_64.rpm-bundle.tar                 mysql-community-icu-data-files-8.0.31-1.el7.x86_64.rpm
mysql-community-client-8.0.31-1.el7.x86_64.rpm           mysql-community-libs-8.0.31-1.el7.x86_64.rpm
mysql-community-client-plugins-8.0.31-1.el7.x86_64.rpm   mysql-community-libs-compat-8.0.31-1.el7.x86_64.rpm
mysql-community-common-8.0.31-1.el7.x86_64.rpm           mysql-community-server-8.0.31-1.el7.x86_64.rpm
mysql-community-debuginfo-8.0.31-1.el7.x86_64.rpm        mysql-community-server-debug-8.0.31-1.el7.x86_64.rpm
mysql-community-devel-8.0.31-1.el7.x86_64.rpm            mysql-community-test-8.0.31-1.el7.x86_64.rpm
mysql-community-embedded-compat-8.0.31-1.el7.x86_64.rpm

部署顺序不能乱,否则可能会提示缺少对应的依赖

mysql-community-common-8.0.31-1.el7.x86_64.rpm
mysql-community-client-plugins-8.0.31-1.el7.x86_64.rpm
mysql-community-libs-8.0.31-1.el7.x86_64.rpm
mysql-community-client-8.0.31-1.el7.x86_64.rpm
mysql-community-icu-data-files-8.0.31-1.el7.x86_64.rpm
mysql-community-server-8.0.31-1.el7.x86_64.rpm

安装 MySQL

# 由于 MySQL 安装过程中,会通过 MySQL 用户在 /tmp 目录下新建 tmp_db 文件。赋予其权限执行:
chmod -R 777 /tmp
# 检查依赖是否存在(CentOS7安装了桌面环境默认存在)
rpm -qa|grep libaio
rpm -qa|grep net-tools
# MySQL 与 mysql-libs 冲突,提前移除
yum remove mysql-libs 或者 rpm -e mariadb-libs --nodeps

# 执行安装(严格按照顺序)
rpm -ivh mysql-community-common-8.0.31-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-plugins-8.0.31-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-8.0.31-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-8.0.31-1.el7.x86_64.rpm
rpm -ivh mysql-community-icu-data-files-8.0.31-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-8.0.31-1.el7.x86_64.rpm

 部署过程遇缺少.so的依赖

[root@jerry src]# rpm -ivh mysql-community-libs-8.0.31-1.el7.x86_64.rpm
警告:mysql-community-libs-8.0.31-1.el7.x86_64.rpm: 头V4 RSA/SHA256 Signature, 密钥 ID 3a79bd29: NOKEY
错误:依赖检测失败:
        mariadb-libs 被 mysql-community-libs-8.0.31-1.el7.x86_64 取代
[root@jerry src]# rpm -e mariadb-libs --nodeps   # 卸载mariadb-libs

[root@jerry src]# rpm -ivh mysql-community-server-8.0.31-1.el7.x86_64.rpm
警告:mysql-community-server-8.0.31-1.el7.x86_64.rpm: 头V4 RSA/SHA256 Signature, 密钥 ID 3a79bd29: NOKEY
错误:依赖检测失败:
        net-tools 被 mysql-community-server-8.0.31-1.el7.x86_64 需要
[root@jerry src]# yum install -y net-tools

简单配置

# 查看是否安装成功
mysql --version
# root用户下进行初始化
mysqld --initialize --user=mysql
# 查看初始密码
cat /var/log/mysqld.log
# 启动 MySQL
systemctl start mysqld
# 查看状态
systemctl status mysqld
# 查看 MySQL 自启动状态
systemctl list-unit-files|grep mysqld.service
# enable 为自启动打开,disable 为自启动关闭
# systemctl enable mysqld(将某服务设置为自启动状态)
# systemctl disable mysqld(将某服务设置为自启动状态)

# 登录 MySQL
mysql -uroot -p
# 修改初始密码(root'@'localhost),如果不修改的密码,其他操作包括修改root'@'%,一切命令都不好使

ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password';

远程连接 Linux 主机的 MySQL

# 关闭本机及远程主机防火墙或开放端口号(本文采用关闭防火墙)
# Linux 下防火墙设置
# 查看防火墙状态
systemctl status firewalld
# 关闭防火墙
systemctl stop firewalld
# 关闭防火墙开机自启动
systemctl disable firewalld

# 启用 MySQl 远程登录权限

方式一:将'root'@'localhost'修改成root'@'%,不推荐

# 切换数据库
use mysql;
# 查看登录权限
select Host,User from user;
# 修改登录权限
update user set host = '%' where user ='root';        # 工作中尽量更严格使用通配符
# 刷新配置文件立即生效
flush privileges;
# 若报错"2058",执行
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'new_password';

方式二:创建一个新的root'@'%

# 默认mysql不带root'@'%的账户

mysql> select host,user from mysql.user;
+-----------+------------------+
| host      | user             |
+-----------+------------------+
| localhost | mysql.infoschema |
| localhost | mysql.session    |
| localhost | mysql.sys        |
| localhost | root             |
+-----------+------------------+
4 rows in set (0.01 sec)

mysql> create user 'root'@'%' identified by '123456';
Query OK, 0 rows affected (0.01 sec)

mysql> grant all privileges on *.* to 'root'@'%' with grant option;
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> select host,user from mysql.user;
+-----------+------------------+
| host      | user             |
+-----------+------------------+
| %         | root             |
| localhost | mysql.infoschema |
| localhost | mysql.session    |
| localhost | mysql.sys        |
| localhost | root             |
+-----------+------------------+
5 rows in set (0.00 sec)

mysql>

Linux(CentOS 7)下安装 MySQL 8.0.31_第3张图片

 修改字符集(MySQL 5.7版本)

# 查看默认字符集
show variables like '%char%';
# 修改字符集,Windows下配置文件为 my.ini ,Linux 下配置文件为 /etc/my.cnf
vim /etc/my.cnf
# 将以下文本追加到最后
character_set_server=utf8
# 重启 MySQL 服务
systemctl restart mysqld
# 原库、原表的设定不会发生变化,参数修改只对新建的数据库生效
# 修改已创建数据库的字符集
alter database dbtest1 character set 'utf8';
# 修改已创建数据表的字符集
alter table t_emp convert to character set 'utf8';

你可能感兴趣的:(#,mysql,mysql)