MySQL专题系列:MySQL 5.7 安装(基于cent os 6.5以上)
1 查看系统中是否自带安装mysql
yum list installed|grep mysql
2 删除系统自带的mysql及其依赖(防止冲突)
yum -y remove mysql-libs.x86_64
3 给CentOS 添加rpm源,并且选择较新的源
wget dev.mysql.com/get/mysql-community-release-el6-5.noarch.rpm
4 安装下载好的rpm文件
yum install mysql-community-release-el6-5.noarch.rpm -y
5 安装成功之后,会在 /etc/yum.repos.d/文件加下增加两个文件
mysql-community.repo mysql-community-source.repo
6 修改mysql-community.repo文件
将mysql 5.6的enabled=1改成enabled=0,并且将mysql 5.7的enabled=0改成enabled=1
7 使用yum安装mysql
yum install mysql-community-server -y
-
Centos7.65安装mysql5.7.28rpm包报错:
Error: Package: 2:postfix-2.10.1-9.el7.x86_64 (base)
Requires: libmysqlclient.so.18(libmysqlclient_18)(64bit)
Removing: 1:mariadb-libs-5.5.60-1.el7_5.x86_64 (installed)
libmysqlclient.so.18(libmysqlclient_18)(64bit)
Obsoleted By: mysql-community-libs-5.7.36-1.el6.x86_64 (mysql57-community-dmr)
Not found
Updated By: 1:mariadb-libs-5.5.68-1.el7.x86_64 (base)
libmysqlclient.so.18(libmysqlclient_18)(64bit)
Error: Package: 2:postfix-2.10.1-9.el7.x86_64 (base)
Requires: libmysqlclient.so.18()(64bit)
Removing: 1:mariadb-libs-5.5.60-1.el7_5.x86_64 (installed)
libmysqlclient.so.18()(64bit)
Obsoleted By: mysql-community-libs-5.7.36-1.el6.x86_64 (mysql57-community-dmr)
~libmysqlclient.so.20()(64bit)
Updated By: 1:mariadb-libs-5.5.68-1.el7.x86_64 (base)
libmysqlclient.so.18()(64bit)
原因是:存在mariadb-libs*
解决办法:卸载mariadb-libs。
# 查找是否存在mariadb依赖包
rpm -qa|grep mariadb
# 卸载
yum remove mariadb-libs
执行上述语句后再执行安装命令
还是报错:
Error: Package: mysql-community-server-5.7.36-1.el6.x86_64 (mysql57-community-dmr)
Requires: libsasl2.so.2()(64bit)
You could try using --skip-broken to work around the problem
You could try running: rpm -Va --nofiles --nodigest
解决方法:修改/etc/yum.repos.d/mysql-community.repo 源文件
vim /etc/yum.repos.d/mysql-community.repo
找到57的 baseurl,将地址中的6改成7即可
[mysql57-community]
name=MySQL 5.7 Community Server
## baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/6/$basearch/
baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/7/$basearch/
enabled=1
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
再执行安装命令,安装成功
8 启动mysql服务并设置开机启动
# 启动mysql服务
service mysqld start
# 设置开机启动
chkconfig mysqld on
9 获取mysql的临时密码
grep "password" /var/log/mysqld.log
10 使用临时密码登录
mysql -uroot -p
# 输入找到的临时密码
11 修改密码
# 修改密码复杂度校验规则
set global validate_password_policy=0;
# 修改密码长度限制
set global validate_password_length=1;
# 修改密码为123456
alter user 'root'@'localhost' identified by '123456';
12 修改远程访问权限
# 授权
# GRANT:赋权命令
# ALL PRIVILEGES:当前用户的所有权限
# ON:介词
# *.*:当前用户对所有数据库和表的相应操作权限
# TO:介词
# 'root'@'%':权限赋给root用户,所有ip都能连接
# IDENTIFIED BY ‘123456’:连接时输入密码,密码为123456
# WITH GRANT OPTION:允许级联赋权
grant all privileges on *.* to 'root'@'%' identified by '123456' with grant option;
# 刷新权限信息
flush privileges;
13 设置字符集为UTF8
# 打开配置文件
vim /etc/my.cnf
# 在[mysqld]部分添加:
character-set-server=utf8
# 在文件末尾新增[client]段,并在[client]段添加:
default-character-set=utf8
14 重启mysql 服务
service mysqld restart