官方安装教程:
https://dev.mysql.com/doc/refman/5.7/en/linux-installation-yum-repo.html
1.查看是否已安装
rpm -qa | grep mysql
如果已安装则删除 MySQL 及其依赖的包
yum -y remove mysql-libs.x86_64
2. 下载源
1.下载 mysql57-community-release-el7-8.noarch.rpm 的 YUM 源:
wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
2.安装 mysql57-community-release-el7-8.noarch.rpm:
yum localinstall mysql57-community-release-el7-8.noarch.rpm
3.检查mysql源是否安装成功
yum repolist enabled | grep "mysql.*-community.*"
[root@hdp02 software]# yum repolist enabled | grep "mysql.*-community.*"
mysql-connectors-community/x86_64 MySQL Connectors Community 212
mysql-tools-community/x86_64 MySQL Tools Community 132
mysql57-community/x86_64 MySQL 5.7 Community Server 524
4. 安装
4.1 安装mysql
安装命令:
yum -y install mysql-community-server
启动:
systemctl start mysqld
4.2 修改密码策略
修改密码策略:
vim /etc/my.cnf
在my.cnf文件添加如下配置禁用密码策略:
validate_password = off
重启mysql
systemctl restart mysqld
4.3 修改密码
- 查找初始密码
[root@hdp02 software]# cat /var/log/mysqld.log | grep 'temporary password'
2021-10-06T13:42:43.755244Z 1 [Note] A temporary password is generated for root@localhost: /EE8N>XKre_,
其中/EE8N>XKre_,
即是初始密码
- 使用默认密码登录mysql进行修改root密码
[root@hdp02 software]# mysql -u root -p
Enter password:
- 修改root用户密码
mysql> ALTER USER ‘root’@‘localhost’ IDENTIFIED BY ‘123456’;
4.4 设置远程访问
本次mysql安装,是为了存放Hive的元数据,所以需要开启远程访问。
以新密码登陆MySQL:
mysql> mysql -uroot -p123456
创建用户:
mysql> create user 'root'@'%' identified by '123456';
允许远程连接:
mysql> grant all privileges on *.* to 'root'@'%' with grant option;
刷新权限:
mysql> flush privileges;
4.5 配置默认编码为utf8
修改/etc/my.cnf配置文件,在[mysqld]下添加编码配置,如下所示:
vim /etc/my.cnf
[mysqld]
character_set_server=utf8
init_connect='SET NAMES utf8'
重新启动mysql服务使配置生效:
systemctl restart mysqld
查看数据库默认编码:
mysql> show variables like '%character%';