1、安装准备
下载mysql5.7的安装包
https://dev.mysql.com/get/mysql-5.7.29-1.el7.x86_64.rpm-bundle.tar
下载后上传至/home目录下
2、mysql5.7安装
2.1、更新yum并安装依赖
bash
yum update -y
sudo yum install -y wget
sudo yum install libaio
sudo yum install perl
sudo yum install net-tools
2.2、检查操作系统是否安装过mysql
bash
rpm -qa | grep -i mysql
##如果有安装请先卸载,卸载命令如下
rpm -e --nodeps ## 对应的软件信息
##卸载mariadb
[root@dss20 mysql]# rpm -qa | grep -i mariadb
mariadb-libs-5.5.68-1.el7.x86_64
[root@dss20 mysql]# rpm -e --nodeps mariadb-libs-5.5.68-1.el7.x86_64
2.2、也可通过wget方式下载MySQL5.7
bash
cd /home
wget https://dev.mysql.com/get/mysql-5.7.29-1.el7.x86_64.rpm-bundle.tar
2.3、解压下载的tar压缩包
bash
tar -xvf mysql-5.7.29-1.el7.x86_64.rpm-bundle.tar
2.4、安装
bash
rpm -ivh mysql-community-common-5.7.29-1.el7.x86_64.rpm mysql-community-libs-5.7.29-1.el7.x86_64.rpm mysql-community-client-5.7.29-1.el7.x86_64.rpm mysql-community-server-5.7.29-1.el7.x86_64.rpm
2.5、mysql初始化设置
bash
#初始化
mysqld --initialize
#更改所属组
chown mysql:mysql /var/lib/mysql -R
#启动mysql
systemctl start mysqld.service
#查看生成的临时root密码
cat /var/log/mysqld.log | grep password
2.6、修改root密码 授权远程访问 设置开机自启动
sql
[root@node2 ~]# mysql -u root -p
Enter password: #这里输入在日志中生成的临时密码,也可从复制粘贴至此处,粘贴后回车即可
mysql>
#更新root密码 设置为123456
mysql> alter user user() identified by "123456";
Query OK, 0 rows affected (0.00 sec)
#授权
mysql> use mysql;
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
mysql> FLUSH PRIVILEGES;
#建议设置为开机自启动服务
mysql>exit;
[root@node2 ~]# systemctl enable mysqld
Created symlink from /etc/systemd/system/multi-user.target.wants/mysqld.service to /usr/lib/systemd/system/mysqld.service.
#查看是否已经设置自启动成功
[root@node2 ~]# systemctl list-unit-files | grep mysqld
mysqld.service enabled
#mysql的启动和关闭 状态查看 (这几个命令常用,需记住)
systemctl stop mysqld
systemctl status mysqld
systemctl start mysqld
2.7、连接验证
2.7.1、创建 dss和hive库
sql
创建 dss和hive库
create database dss default character set utf8mb4 COLLATE utf8mb4_general_ci;
CREATE USER 'dss'@'%' IDENTIFIED BY '123456';
GRANT ALL PRIVILEGES ON dss.* TO 'dss'@'%';
create database hive default character set utf8mb4 COLLATE utf8mb4_general_ci;
CREATE USER 'hive'@'%' IDENTIFIED BY '123456';
GRANT ALL PRIVILEGES ON hive.* TO 'hive'@'%';
FLUSH PRIVILEGES;
exit;