1、安装新版mysql前,需将系统自带的mariadb-lib卸载
rpm -qa|grep mariadb
[[email protected]]# mariadb-libs-5.5.44-2.el7.centos.x86_64
rpm -e --nodeps mariadb-libs-5.5.44-2.el7.centos.x86_64
2、下载mysql离线包
下载地址:https://dev.mysql.com/downloads/mysql/#downloads
解压:tar xvf mysql-5.7.16-1.el7.x86_64.rpm-bundle.tar
3、安装
使用rpm -ivh命令依次进行安装
rpm -ivh mysql-community-common-5.7.16-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-5.7.16-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-5.7.16-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-5.7.16-1.el7.x86_64.rpm
4、初始化数据库
// 指定datadir, 执行后会生成(~/.mysql_secret)或(/var/log/mysqld.log)密码文件
[[email protected]]# mysqld --initialize --datadir=/var/lib/mysql
5、更改mysql数据库目录的所属用户及其所属组,并启动mysql数据库
[[email protected]]# chown mysql:mysql /var/lib/mysql -R
[[email protected]]# systemctl start mysqld.service
6、登录到mysql,更改root用户的密码
// password 通过 cat ~/.mysql_secret 命令可以查看初始密码
[[email protected] mytmp]# mysql -uroot -p
Enter password:
mysql> set password=password(‘mysql‘);
7、设置mysql开机启动
// 检查是否已经是开机启动
systemctl list-unit-files | grep mysqld
// 开机启动
systemctl enable mysqld.service
8、创建用户,分配权限,远程登陆授权
mysql -uroot -pmysql
GRANT ALL PRIVILEGES ON *.* TO ‘root‘@‘%‘ IDENTIFIED BY ‘mysql‘ WITH GRANT OPTION;
FLUSH PRIVILEGES;
初始化hive库
mysql -u root -pmysql
CREATE USER ‘hive‘@‘%‘ IDENTIFIED BY ‘hive‘;
GRANT ALL PRIVILEGES ON *.* TO ‘hive‘@‘%‘;
CREATE USER ‘hive‘@‘localhost‘ IDENTIFIED BY ‘hive‘;
GRANT ALL PRIVILEGES ON *.* TO ‘hive‘@‘localhost‘;
CREATE USER ‘hive‘@‘host-name‘ IDENTIFIED BY ‘hive‘;
GRANT ALL PRIVILEGES ON *.* TO ‘hive‘@‘host-name‘;
FLUSH PRIVILEGES;
CREATE DATABASE `hive` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;