Linux-mysql5.7.21安装

Linux -redhat 7.0安装mysql5.7.21

这是自己第一次在linux中安装mysql软件,记录一下安装的过程,方便有需要的人可以安装,mysql的安装是采用rpm的方式。

1.查询自己的Linux版本

[root@localhost ~]# cat /etc/redhat-release
Red Hat Enterprise Linux Server release 7.0 (Maipo)
[root@localhost ~]# getconf LONG_BIT
64

2.下载mysql 5.7.21

到mysql的官网下载,注意自己下的版本号。我这里用的是64位mysql5.7.21.
MySQL下载
在这里插入图片描述

3.上传mysql到Linux

使用Xftp工具将mysql的文件包上传到Linux中
在这里插入图片描述

4.卸载

先查看本虚拟机有没有安装到mysql,因为是Red Hat 的Linux,默认安装的是mariadb数据库,查看是否安装rpm -qa|grep mariadb,卸载执行rpm -e --nodeps (xxxxxxxxxx)

5.创建mysql目录

[root@localhost ~]# cd /usr/local
[root@localhost local]# mkdir mysql
[root@localhost local]# cd mysql

6.解压

将文件移到mysql目录下,并解压

[root@localhost ~]# mv mysql-5.7.21-1.el7.x86_64.rpm-bundle.tar /usr/local/mysql
[root@localhost ~]# cd /usr/local/mysql
[root@localhost mysql]# ll
总用量 580020
-rw-r--r--. 1 root root 593940480 7月  11 21:58 mysql-5.7.21-1.el7.x86_64.rpm-bundle.tar
[root@localhost mysql]# 
[root@localhost mysql]# tar -xvf mysql-5.7.21-1.el7.x86_64.rpm-bundle.tar 
mysql-community-embedded-devel-5.7.21-1.el7.x86_64.rpm
mysql-community-minimal-debuginfo-5.7.21-1.el7.x86_64.rpm
mysql-community-common-5.7.21-1.el7.x86_64.rpm
mysql-community-libs-compat-5.7.21-1.el7.x86_64.rpm
mysql-community-embedded-compat-5.7.21-1.el7.x86_64.rpm
mysql-community-server-minimal-5.7.21-1.el7.x86_64.rpm
mysql-community-client-5.7.21-1.el7.x86_64.rpm
mysql-community-server-5.7.21-1.el7.x86_64.rpm
mysql-community-embedded-5.7.21-1.el7.x86_64.rpm
mysql-community-test-5.7.21-1.el7.x86_64.rpm
mysql-community-devel-5.7.21-1.el7.x86_64.rpm
mysql-community-libs-5.7.21-1.el7.x86_64.rpm

7.安装

解压之后又很多文件,我们只需要安装主要的文件即可,一定要注意顺序;
rpm -ivh mysql-community-common-5.7.21-1.el7.x86_64.rpm

在这里插入图片描述

  • 安装完后开始初始化数据库,进入/usr/bin;
  • mysqld --initialize --user=mysql为root用户随机生成一个登陆密码;
  • 查看密码 vi /var/log/mysqld.log
  • 文件末尾中有root@localhost: **********
    密码就为: ******
  • 复制它
[root@localhost usr]# cd bin
[root@localhost bin]# mysqld --initialize --user=mysql
[root@localhost bin]# mysql -u root -p
Enter password: 
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
[root@localhost bin]# vi /var/log/mysqld.log

在这里插入图片描述

  • 上面显示还没有启动mysq服务
  • 启动该服务

在这里插入图片描述

  • 最后登录就可以了
[root@localhost bin]# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.7.21
  • 还有个登录后要重置密码的,没有截到图,
mysql >set password=password('123456');
mysql >show databases;
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值