Linux 7(CentOS、Redhat)安装MySQL

Linux 7(CentOS、Redhat等)安装MySQL

本期跟大家介绍一下Linux7(包含CentOS、Redhat等)安装MySQL5的安装。

出于MySQL安装rpm及其依赖的困扰,我打包好了安装MySQL相关包,可直接下载,然后通过fileZilla或x-shell等软件传到自己服务器上。

链接https://pan.baidu.com/s/1l_lrSGSIkq8fX6G9mlaOmQ
提取码:93fp

安装前准备:

1. 检查机器是否安装过MySQL或MariaDB,有的话需要先卸载
[root@Jason mysql]# rpm -qa | grep mysql
[root@Jason mysql]# rpm -qa | grep mariadb
  • 如果有的话就卸载:
[root@Jason mysql]# rpm -e --nodeps 
2. 检查机器上是否有MariaDB或MySQL的文件,有的话删除
[root@Jason mysql]# ll /var/lib | grep mysql
[root@Jason mysql]# find / -name mariadb
# 有的话就删除没有就忽略
[root@Jason mysql]# rm -rf /var/lib/mysql

安装步骤:

1. 首先进入自己服务器,新建个文件夹用来保存解压后的rpm包:
[root@Jason mysql]# cd /software/mysql/
[root@Jason mysql]# ls
mysql-5.7.21-1.tar
[root@Jason mysql]# tar -xf mysql-5.7.21-1.tar
[root@Jason mysql]# ll
总用量 1160048
-rw-r--r--. 1 root root  593940480 11月 22 16:57 mysql-5.7.21-1.tar
-rw-r--r--. 1 7155 31415  25107316 12月 28 2017 mysql-community-client-5.7.21-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415    278844 12月 28 2017 mysql-community-common-5.7.21-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415   3779988 12月 28 2017 mysql-community-devel-5.7.21-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415  46256768 12月 28 2017 mysql-community-embedded-5.7.21-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415  24078148 12月 28 2017 mysql-community-embedded-compat-5.7.21-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415 128571868 12月 28 2017 mysql-community-embedded-devel-5.7.21-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415   2238596 12月 28 2017 mysql-community-libs-5.7.21-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415   2115904 12月 28 2017 mysql-community-libs-compat-5.7.21-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415  55662616 12月 28 2017 mysql-community-minimal-debuginfo-5.7.21-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415 171890056 12月 28 2017 mysql-community-server-5.7.21-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415  15289580 12月 28 2017 mysql-community-server-minimal-5.7.21-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415 118654584 12月 28 2017 mysql-community-test-5.7.21-1.el7.x86_64.rpm
2. 安装MySQL
  • 由于MySQL各个包的依赖关系,需要按顺序进行安装
[root@Jason mysql]# rpm -ivh mysql-community-common-5.7.21-1.el7.x86_64.rpm
[root@Jason mysql]# rpm -ivh mysql-community-libs-5.7.21-1.el7.x86_64.rpm
[root@Jason mysql]# rpm -ivh mysql-community-client-5.7.21-1.el7.x86_64.rpm
[root@Jason mysql]# rpm -ivh mysql-community-server-5.7.21-1.el7.x86_64.rpm
  • 说明:安装mysql-community-server包时需要 net-tools ,这个正常yum中都有的,使用下边指令安装下即可
[root@Jason mysql]# yum install -y net-tools
3. 初始化MySQL
  • 上边的包安装完后初始化MySQL,生成MySQL密码
[root@Jason mysql]# mysqld --initialize --user=mysql
  • 执行完去 /var/log/mysql.log中查看密码,root@localhost 后的就是初始密码,为了方便我直接获取
[root@Jason mysql]# cat /var/log/mysql.log | grep local
2021-11-22T09:14:39.221746Z 1 [Note] A temporary password is generated for root@localhost: )JQ<qm3J&Ujy
2021-11-22T09:16:30.001382Z 2 [Note] Access denied for user 'root'@'localhost' (using password: YES)
  • 从中可以看到密码就是 )JQ<qm3J&Ujy
4. 开启MySQL服务
[root@Jason mysql]# systemctl start mysqld
# 然后查看是否已启动
[root@Jason mysql]# systemctl status mysqld
● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: active (running) since 一 2021-11-22 17:14:54 CST; 21h ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
  Process: 4386 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
  Process: 4304 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
 Main PID: 4389 (mysqld)
   CGroup: /system.slice/mysqld.service
           └─4389 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid

11月 22 17:14:36 bigdata systemd[1]: Starting MySQL Server...
11月 22 17:14:54 bigdata systemd[1]: Started MySQL Server.
5. 登录MySQL
  • 如果有报错就 mysql -uroot -p 之后按提示输出密码
[root@Jason mysql]# mysql -uroot -p)JQ<qm3J&Ujy
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.7.21 MySQL Community Server (GPL)

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 

这样MySQL就安装完成了,如果嫌密码太负责想设置成简单的,比如 123456 之类的,可以参考下我另一篇文章设置两个参数后就可以。
传送门: https://blog.csdn.net/weixin_45579026/article/details/121492275

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

程序员老五

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值