首页 > 数据库 >CentOS安装Mysql5

CentOS安装Mysql5

时间:2023-03-23 17:14:58浏览次数:74  
标签:安装 Mysql5 CentOS root community 64 mysql rpm x86

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安装

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

相关文章

  • Acrobat Pro DC2019 软件下载安装
    软件介绍:AdobeAcrobat是由Adobe公司开发的一款PDF(PortableDocumentFormat,便携式文档格式)编辑软件。借助它,您可以以PDF格式制作和保存你的文档,以便于浏览和打印,或使用......
  • Nginx安装部署
    title:Nginx安装部署date:2022-10-26tags:-Linux-Nginxcategories:-运维-Nginxkeywords:'Linux,Nginx'description:Nginx安装部署cover:https://q......
  • Keepalived安装部署
    title:Keepalived安装部署date:2022-10-22tags:-Linux-keepalivecategories:-运维-Nginx-keepalivedkeywords:'Linux,keepalived'cover:https://q......
  • 源码安装nginx,平滑升级nginx,nginx认证和访问控制
    Nginx是俄罗斯人编写的十分轻量级的HTTP服务器是一个高性能的HTTP和反向代理服务器,同时也是一个IMAP/POP3/SMTP代理服务器【官方网站:http://nginx.org】源码安装Nginx#......
  • 安装宝塔面板
    宝塔面板一、安装宝塔面板2分钟装好面板,一键管理服务器,集成LAMP/LNMP环境安装,网站、FTP、数据库、文件管理、软件安装等功能宝塔面板下载,免费全能的服务器运维软件(bt.......
  • centos7虚拟机静态ip
    1、查看网关       2、查看ip   vi配置进入vi/etc/sysconfig/network-scripts/ifcfg-ens33(文件后缀可能不一样)   重启网络 system......
  • docker安装seata1.4.2
    dockerrun-d--restart=always--nameseata-p8091:8091-v/root/seata/seata-server:/seata-server-eSEATA_IP=127.0.0.1-eSEATA_PORT=8091seataio/seata-serv......
  • 安装 npm 包时无法解决 Angular 中的依赖树错误
    转载:https://www.angularjswiki.com/angular/unable-to-resolve-dependency-tree-error-in-angular-while-installing-npm-packages/修复Unabletoresolvedependency......
  • hydra安装——AttributeError: module ‘hydra‘ has no attribute ‘main‘
    AttributeError:module‘hydra’hasnoattribute‘main’问题1.使用如下方法安装hydra,pipinstallhydra,运行后报错AttributeError:module'hydra'hasnoattribute......
  • 安装纯净windows10操作系统
    有些同学的个人电脑时间长了就会出现卡顿,蓝屏现象,工作、学习受到很大的困扰,自己重新安装windows系统怕中毒或是安装的不是纯净版,自带很多流氓软件等等。现在我来教大家用最......