9.1 mysql8安装
# cd /opt
9.1.1 安装MySQL Server
因为CentOS 7默认安装的数据库是Mariadb,所以使用YUM命令是无法安装MySQL的,只会更新Mariadb。
因此使用rpm来进行安装。
这里,我们使用国内的清华大小的镜像源安装,地址:
清华大学开源镜像源
添加国内安装源并安装
切换目录,如果没有,需新建:
下载:
# wget http://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql80-community-el7/mysql80-community-release-el7-1.noarch.rpm
安装
# rpm -ivh mysql80-community-release-el7-1.noarch.rpm
下载完成后,yum安装:
# yum install mysql-server
如果显示以下内容说明安装成功:
Complete!
检查是否已经设置为开机启动MySQL服务
# systemctl list-unit-files|grep mysqld
则表示已经设置为开机启动,如果没有设置为开机启动则执行
# systemctl enable mysqld.service
9.1.2 启动MySQL
# systemctl start mysqld.service
初始化
# mysqld --initialize
查看默认密码
# grep 'temporary password' /var/log/mysqld.log
localhost后面的最后的那一大串字符,就是密码,复制下来。【 7ZWYzNEIgJ+7】
登录
# mysql -uroot -p
输入刚刚的密码。【 7ZWYzNEIgJ+7】
重置root密码
> alter user 'root'@'localhost' identified by '12345678';
建议设置较为复杂的密码。
如果设置密码时候出现提示:
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
执行:
> set global validate_password.policy=0;
9.1.3 新建用户
建议不要使用root用户作为日常开发,新建一个用户使用:
> create user 'hadoop'@'localhost' identified by 'hadoop123';
授予全部权限:
> GRANT ALL PRIVILEGES ON *.* TO 'hadoop'@'localhost' WITH GRANT OPTION;
刷新:
> flush privileges;