1.CentOS7下安装mysql8
CentOS7(链接:https://pan.baidu.com/s/1ufvFykiS0DPv-uvFgLDlYQ 提取码:oa91 )
MySQL(链接:https://pan.baidu.com/s/11P_P-9Kqmg5VHRJrjG5auw 提取码:7w49)
1.1下载mysql安装包
https://dev.mysql.com/downloads/mysql/
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-WLuGKgP6-1607067334708)(./assets/Mysql/mysql.png)]
1.2安装mysql
1). 卸载 centos 中预安装的 mysql
rpm -qa | grep -i mysql
rpm -e mysql-libs-5.1.71-1.el6.x86_64 --nodeps(这步还没操作不知对错)
2). 上传 mysql 的安装包
alt + p -------> put D:/mysql-8.0.22-1.el7.x86_64.rpm-bundle.tar
3). 解压 mysql 的安装包
cd root (上传的压缩包在root目录下)
mkdir mysql
tar -xvf mysql-8.0.22-1.el7.x86_64.rpm-bundle.tar -C /root/mysql
cd mysql(进入mysql包,为下一步安装做准备)
4). 安装依赖包
a.安装mysql-community-client-plugins包
rpm -ivh mysql-community-client-plugins-8.0.22-1.el7.x86_64.rpm
b.卸载CentOS7自带的mariadb-libs数据库
rpm -qa | grep mariadb
rpm -e --nodeps mariadb-libs-5.5.52-1.el7.x86_64
(版本根据上一步查出来的,--nodeps强制卸载)
c.安装mysql-community-common包
rpm -ivf mysql-community-common-8.0.22-1.el7.x86_64.rpm
d.安装mysql-community-libs包
rpm -ivf mysql-community-libs-8.0.22-1.el7.x86_64.rpm
5). 安装 mysql-client
rpm -ivh mysql-community-client-8.0.22-1.el7.x86_64.rpm
6). 安装 mysql-server
rpm -ivh mysql-community-server-8.0.22-1.el7.x86_64.rpm
1.3 启动mysql
systemctl start mysqld.service
systemctl status mysqld.service
1.4 登陆mysql
1).首次登陆查看临时密码
grep "password" /var/log/mysqld.log
mysql -uroot -p临时密码
2)重新设置密码
mysql为了安全性,默认validate_password.policy=1,即设置的密码必须长度要大于8位数,并且必须包含有数 字,小写或大写字母,特殊字符。
ALTER USER 'root'@'localhost' IDENTIFIED BY '123qweasdZXC.'
3)退出后重新登陆
quit
mysql -uroot -p密码
拓展:可修改密码规则,具体参数如下
SHOW VARIABLES LIKE 'validate_password%';
+--------------------------------------+--------+
| Variable_name | Value |
+--------------------------------------+--------+
| validate_password.check_user_name | ON |
| validate_password.dictionary_file | |
| validate_password.length | 8 |密码长度>=8
| validate_password.mixed_case_count | 1 |密码中特殊字符的长度
| validate_password.number_count | 1 |密码中数字的长度
| validate_password.policy | MEDIUM |0:LOW;1:MEDIUM(默认);2:STRONG
| validate_password.special_char_count | 1 |密码中特殊字符的长度
+--------------------------------------+--------+
如:
set validate_password.policy=0
ALTER USER 'root'@'localhost' IDENTIFIED BY '12345678'
1.5 其他问题
1).缺少依赖/usr/bin/perl
安装server时报错(参考https://blog.csdn.net/zy_1995/article/details/102588103)
(其他CentOS上遇到,暂未解决)
[root@localhost mysql]# rpm -ivh mysql-community-server-8.0.22-1.el7.x86_64.rpm
警告:mysql-community-server-8.0.22-1.el7.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
错误:依赖检测失败:
/usr/bin/perl 被 mysql-community-server-8.0.22-1.el7.x86_64 需要
perl(Getopt::Long) 被 mysql-community-server-8.0.22-1.el7.x86_64 需要
perl(strict) 被 mysql-community-server-8.0.22-1.el7.x86_64 需要
2)缺少依赖libaio.so
在阿里云ECS服务器上安装mysql-server时报错
error: Failed dependencies:
libaio.so.1()(64bit) is needed by mysql-community-server-8.0.22-1.el7.x86_64
libaio.so.1(LIBAIO_0.1)(64bit) is needed by mysql-community-server-8.0.22-1.el7.x86_64
libaio.so.1(LIBAIO_0.4)(64bit) is needed by mysql-community-server-8.0.22-1.el7.x86_64
解决方案
安装服务器前先安装依赖libaio.so,然后再执行之前的6).安装 mysql-server下的安装命令
安装命令:yum install libaio
3)MySQL随机生成的临时密码中有特殊字符
最近一次安装时,随机临时密码中有特殊字符“;”等,直接用mysql -uroot -p临时密码登陆时就会报错无法登陆
A temporary password is generated for root@localhost: i/;T7fwo?.k;
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
-bash: T7fwo?.k: command not found
解决方案
1、直接将密码用单引号引起来。
2、在特殊字符&前面加上'\'来进行登录。
我这次直接加单引号登陆成功:mysql -uroot -p'i/;T7fwo?.k;'