title: CentOS安装Mysql5.7
date: 2022-08-14 17:45:50
tags:
- Linux
- CentOS
- Mysql
categories:
- 运维
- 数据库
- Mysql
keywords: 'Linux,CentOS,Mysql'
description: CentOS安装Mysql5.7
cover: https://qiufuqi.gitee.io/img/hexo/mysql_install.jpg
abbrlink: centos_mysql5.7
comments: false
Linux环境中安装Mysql5.7,系统版本centos7.6。
Mysql5.7安装
本文总共包含4种安装方式,均通过验证,推荐使用yum安装(最新版本),rpm可安装指定版本,安装包可安装指定版本。
安装方式如下:
- YUM安装
- RPM安装
- 安装包安装
- docker安装
YUM安装
Mysql5.7 YUM下载地址
卸载之前版本
# rpm -e +安装包 或 yum remove +安装包
# rpm -ev --nodeps +安装包 强制删除
[root@localhost ~]# rpm -qa|grep mariadb
mariadb-libs-5.5.68-1.el7.x86_64
[root@localhost ~]# rpm -e --nodeps mariadb-libs-5.5.68-1.el7.x86_64
[root@localhost ~]# yum remove mysql-*
下载rpm文件
wget https://repo.mysql.com/yum/mysql-5.7-community/el/7/x86_64/mysql57-community-release-el7-10.noarch.rpm
安装Mysql
# 安装发行文件
yum -y localinstall mysql57-community-release-el7-10.noarch.rpm
或
rpm -ivh mysql57-community-release-el7-10.noarch.rpm
# 查看mysql版本
yum whatprovides mysql-community-server
# 原因是Mysql的GPG升级了,需要重新获取
rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
# 安装mysql 会有报错
yum -y install mysql-community-server
启动Mysql
systemctl start mysqld
systemctl enable mysqld
重置密码
# 查看临时密码
[root@localhost ~]# cat /var/log/mysqld.log |grep password
2022-08-25T08:25:32.680447Z 1 [Note] A temporary password is generated for root@localhost: XcrEJlRho0_b
# 进入mysql 降低密码要求 可不做
mysql -uroot -p
set global validate_password_policy=0;
set global validate_password_length=1;
set password for root@localhost = password('root');
开放远程连接
use mysql;
update user set user.Host='%' where user.User='root';
flush privileges;
RPM安装
Mysql5.7 RPM下载地址
卸载之前版本
# rpm -e +安装包 或 yum remove +安装包
# rpm -ev --nodeps +安装包 强制删除
[root@localhost ~]# rpm -qa|grep mariadb
mariadb-libs-5.5.68-1.el7.x86_64
[root@localhost ~]# rpm -e --nodeps mariadb-libs-5.5.68-1.el7.x86_64
[root@localhost ~]# yum remove mysql-*
下载rpm文件
wget https://repo.mysql.com/yum/mysql-5.7-community/el/7/x86_64/mysql-community-common-5.7.31-1.el7.x86_64.rpm
wget https://repo.mysql.com/yum/mysql-5.7-community/el/7/x86_64/mysql-community-libs-5.7.31-1.el7.x86_64.rpm
wget https://repo.mysql.com/yum/mysql-5.7-community/el/7/x86_64/mysql-community-client-5.7.31-1.el7.x86_64.rpm
wget https://repo.mysql.com/yum/mysql-5.7-community/el/7/x86_64/mysql-community-server-5.7.31-1.el7.x86_64.rpm
安装Mysql
rpm -ivh mysql-community-common-5.7.31-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-5.7.31-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-5.7.31-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-5.7.31-1.el7.x86_64.rpm
启动Mysql
systemctl start mysqld
systemctl enable mysqld
重置密码
# 查看临时密码
[root@localhost ~]# cat /var/log/mysqld.log |grep password
2022-08-25T08:25:32.680447Z 1 [Note] A temporary password is generated for root@localhost: IqYx0nr/VEk7
# 进入mysql 降低密码要求 可不做
mysql -uroot -p
set global validate_password_policy=0;
set global validate_password_length=1;
set password for root@localhost = password('root');
开放远程连接
use mysql;
update user set user.Host='%' where user.User='root';
flush privileges;
安装包安装
Mysql5.7安装包下载地址
卸载之前版本
卸载mariadb 和 mysql
# rpm -e +安装包 或 yum remove +安装包
# rpm -ev --nodeps +安装包 强制删除
# 卸载mariadb 和 mysql
[root@localhost ~]# rpm -qa|grep mariadb
mariadb-libs-5.5.68-1.el7.x86_64
[root@localhost ~]# rpm -e --nodeps mariadb-libs-5.5.68-1.el7.x86_64
[root@localhost ~]# yum remove mysql-*
创建MySQL用户组
# 检查mysql 用户组是否存在
cat /etc/group | grep mysql
cat /etc/passwd |grep mysql
# 创建mysql 用户组和用户
groupadd mysql
useradd -r -g mysql mysql
获取安装包
wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.31-linux-glibc2.12-x86_64.tar.gz
解压mysql
tar -zxvf mysql-5.7.34-linux-glibc2.12-x86_64.tar.gz
mv mysql-5.7.34-linux-glibc2.12-x86_64 /usr/local/mysql/
创建数据和⽇志⽬录
chown -R mysql:mysql /usr/local/mysql
chmod -R 755 /usr/local/mysql
初始化mysqld
#务必记住数据库管理员临时密码 可指定文件夹
/usr/local/mysql/bin/mysqld --initialize --user=mysql --datadir=/usr/local/mysql/data --basedir=/usr/local/mysql
编写配置文件my.cnf
[root@localhost ~]# vi /etc/my.cnf
[mysqld]
datadir=/usr/local/mysql/data
port = 3306
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
symbolic-links=0
max_connections=400
innodb_file_per_table=1
# 表名大小写不明感
lower_case_table_names=1
启动mysql
# 添加软连接
ln -s /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
ln -s /usr/local/mysql/bin/mysql /usr/bin/mysql
# 重启mysql服务
systemctl daemon-reload
systemctl start mysqld.service
登录mysql
#密码就是初始化时生成的临时密码
mysql -u root -p
修改密码
set password for root@localhost = password('root');
开放远程连接
use mysql;
update user set user.Host='%' where user.User='root';
flush privileges;
设置开机自启
#赋予可执行权限
chmod +x /etc/init.d/mysqld
#添加服务
chkconfig --add mysqld
#显示服务列表
chkconfig --list
标签:安装,Mysql5,CentOS,root,community,64,mysql,rpm,x86
From: https://www.cnblogs.com/qiufuqi/p/17248143.html