Linux虚拟机 CentOS 7 安装 mysql 教程
简单直接的告诉你需要执行哪些命令,五分钟搞定。
背景: macOS (windows 安装centos7 虚拟机即可)
要求: 安装mysql 5.7
1. 选择安装路径
[root@bigdata01 opt]# cd soft/`
2. 下载安装包
[root@bigdata01 soft]# wget https://dev.mysql.com/get/mysql57-community-release-el7- 11.noarch.rpm
3. 安装mysql
[root@bigdata01 soft]# yum -y install mysql57-community-release-el7-10.noarch.rpm
4. 这里开始有坑,解决 【Failed to start mysqld.service: Unit not found】
[root@bigdata01 soft]# systemctl start mysqld.service
Failed to start mysqld.service: Unit not found.
原因:MySQL在CentOS7中收费了,所以已经不支持MySQL了,取而代之在CentOS7内部集成了mariadb,而安装MySQL的话会和MariaDB的文件冲突,mariadb是mysql的一个分支
解决:
[root@bigdata01 soft]# yum install -y mariadb-server
5. ok 查看状态
[root@bigdata01 soft]# systemctl start mysqld.service
[root@bigdata01 soft]# systemctl status mysqld.service
6. 查看mysql初始密码
[root@bigdata01 soft]# grep "password" /var/log/mysqld.log
7. 更改密码,报错,密码太简单
提示:Your password does not satisfy the current policy requirements
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
8. 执行这两行命令,6代表密码长度
mysql> set global validate_password_policy=0;
mysql> set global validate_password_length=6;
9. 可以设置你的密码了!比如6位数
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
10. 赋权限
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456';
mysql> flush privileges;