帮你踩坑linux安装mysql8

作者: singworld 分类: mysql,未分类 发布时间: 2019-07-08 23:36

1.安装

安装前,我们可以检测系统是否自带安装 MySQL:
rpm -qa | grep mysql
如果你系统有安装,那可以选择进行卸载:
rpm -e mysql  // 普通删除模式
rpm -e –nodeps mysql  // 强力删除模式,如果使用上面命令删除时,提示有依赖的其它文件,则用该命令可以对其进行强力删除
安装 MySQL:
接下来我们在 Centos7 系统下使用 yum 命令安装 MySQL,需要注意的是 CentOS 7 版本中 MySQL数据库已从默认的程序列表中移除,所以在安装前我们需要先去官网下载 Yum 资源包,下载地址为:https://dev.mysql.com/downloads/repo/yum/
screenshot.jpeg

wget http://repo.mysql.com/mysql80-community-release-el7-3.noarch.rpm
rpm -ivh mysql80-community-release-el7-3.noarch.rpm
yum update
yum install mysql-server


推荐使用阿里源的yum,国内使用可以大幅提升下载速度(可跳过)

1、备份
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
  

2、下载新的CentOS-Base.repo 到/etc/yum.repos.d/
CentOS 5
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-5.repo
或者
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-5.repo

CentOS 6
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
或者
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo

CentOS 7
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
或者
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
  

3、之后运行yum makecache生成缓存
yum clean all
yum makecache


3启动验证mysql

权限设置:
chown mysql:mysql -R /var/lib/mysql
初始化 MySQL:
mysqld –initialize
启动 MySQL:
systemctl start mysqld
查看 MySQL 运行状态:
systemctl status mysqld

验证安装
[root@host]# mysqladmin –version
linux上该命令将输出以下结果,该结果基于你的系统信息:
mysqladmin Ver 8.23 Distrib 5.0.9-0, for redhat-linux-gnu on i386

4深坑到来

跳过密码登陆

vim /etc/my.cnf
添加skip-grant-table
systemctl stop mysqld.service
systemctl start mysqld.service
mysql –u root
[敲回车进入]
mysql> flush privileges;

1.清空密码
use mysql;
update user set authentication_string=” where user=’root’;
2.修改host不然不能本地和远程连接
update user set host=’%’ where user=’root’;
3.修改密码
ALTER USER ‘root’@’%’ IDENTIFIED WITH mysql_native_password BY ‘123’;

去除跳过密码登陆
#vim /etc/my.cnf
注释或删除skip-grant-table
#systemctl stop mysqld.service
#systemctl start mysqld.service

systemctl restart mysqld 重启

Leave a Reply

Your email address will not be published. Required fields are marked *