【爆肝总结_新手看完必会】Linux操作系统⭐Centos7⭐如何安装MySQL⭐_超级详细,新手小白看完就会搭建❤️常见错误❤️常用语句❤️总结归纳❤️

清华的镜像简单下载

清华大学开源软件镜像站

https://mirror.tuna.tsinghua.edu.cn/

1.详细图示💎🍭

①.❤️搜索MySQL

在这里插入图片描述

②.❤️点击下载

在这里插入图片描述

③.❤️找到版本为MySQL-5.7/mysql-5.7.34-1.el7.x86_64.rpm-bundle.tar

在这里插入图片描述
右键复制地址备用
在这里插入图片描述

2. 打开虚拟机💎🍭

①.❤️开始给Linux安装MySQL压缩包

[root@oldgirl ~]# wget https://mirror.tuna.tsinghua.edu.cn/mysql/downloads/MySQL-5.7/mysql-5.7.34-1.el7.x86_64.rpm-bundle.tar
--2021-10-09 12:50:59--  https://mirror.tuna.tsinghua.edu.cn/mysql/downloads/MySQL-5.7/mysql-5.7.34-1.el7.x86_64.rpm-bundle.tar
正在解析主机 mirror.tuna.tsinghua.edu.cn (mirror.tuna.tsinghua.edu.cn)... 101.6.15.130, 2402:f000:1:400::2
正在连接 mirror.tuna.tsinghua.edu.cn (mirror.tuna.tsinghua.edu.cn)|101.6.15.130|:443... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:543856640 (519M) [application/octet-stream]
正在保存至: “mysql-5.7.34-1.el7.x86_64.rpm-bundle.tar”

100%[==============================>] 543,856,640  885KB/s 用时 15m 54s

2021-10-09 13:06:54 (557 KB/s) - 已保存 “mysql-5.7.34-1.el7.x86_64.rpm-bundle.tar” [543856640/543856640])

②.❤️检查是否安装了mysql,如果原来有就卸载原先的

[root@oldgirl ~]#  rpm -qa | grep mysql

删除方式:
[root@oldgirl ~]# rpm -e 文件

③.❤️检查是否安装了mariadb,如果原来有就卸载原先的

[root@oldgirl ~]#  rpm -qa | grep mariadb

删除方式:
[root@oldgirl ~]# rpm -e 文件

3.创建一个mysql解压的目录💎🍭

[root@oldgirl ~]# mkdir mysql
[root@oldgirl ~]# ls
a                b  d      mysql-5.7.34-1.el7.x86_64.rpm-bundle.tar
anaconda-ks.cfg  c  mysql  人1.xls

4.开始解压💎🍭

[root@oldgirl ~]# tar xvf mysql-5.7.34-1.el7.x86_64.rpm-bundle.tar -C ./mysql
mysql-community-client-5.7.34-1.el7.x86_64.rpm
mysql-community-common-5.7.34-1.el7.x86_64.rpm
mysql-community-devel-5.7.34-1.el7.x86_64.rpm
mysql-community-embedded-5.7.34-1.el7.x86_64.rpm
mysql-community-embedded-compat-5.7.34-1.el7.x86_64.rpm
mysql-community-embedded-devel-5.7.34-1.el7.x86_64.rpm
mysql-community-libs-5.7.34-1.el7.x86_64.rpm
mysql-community-libs-compat-5.7.34-1.el7.x86_64.rpm
mysql-community-server-5.7.34-1.el7.x86_64.rpm
mysql-community-test-5.7.34-1.el7.x86_64.rpm

有这么多rpm包,我们主要安装4个,继续看下文

5.注意4个rpm包安装顺序💎🍭

❤️第一步❤️创建 mysql-community-common-5.7.34-1.el7.x86_64.rpm

[root@oldgirl mysql]# rpm -ivh mysql-community-common-5.7.34-1.el7.x86_64.rpm
警告:mysql-community-common-5.7.34-1.el7.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
准备中...                          ################################# [100%]
正在升级/安装...
   1:mysql-community-common-5.7.34-1.e################################# [100%]

❤️第二步❤️创建 mysql-community-libs-compat-5.7.34-1.el7.x86_64.rpm

[root@oldgirl mysql]# rpm -ivh mysql-community-libs-5.7.34-1.el7.x86_64.rpm
警告:mysql-community-libs-5.7.34-1.el7.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
准备中...                          ################################# [100%]
正在升级/安装...
   1:mysql-community-libs-5.7.34-1.el7################################# [100%]

❤️第三步❤️创建 mysql-community-client-5.7.34-1.el7.x86_64.rpm

[root@oldgirl mysql]# rpm -ivh mysql-community-client-5.7.34-1.el7.x86_64.rpm
警告:mysql-community-client-5.7.34-1.el7.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
准备中...                          ################################# [100%]
正在升级/安装...
   1:mysql-community-client-5.7.34-1.e################################# [100%]

❤️第四步❤️创建 mysql-community-server-5.7.34-1.el7.x86_64.rpm

[root@oldgirl mysql]# rpm -ivh mysql-community-server-5.7.34-1.el7.x86_64.rpm
警告:mysql-community-server-5.7.34-1.el7.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
准备中...                          ################################# [100%]
正在升级/安装...
   1:mysql-community-server-5.7.34-1.e################################# [100%]

第四步常见❤️错误❤️以及如何解决

[root@oldgirl mysql]# rpm -ivh mysql-community-server-5.7.34-1.el7.x86_64.rpm
警告:mysql-community-server-5.7.34-1.el7.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
错误:依赖检测失败:
	/usr/bin/perl 被 mysql-community-server-5.7.34-1.el7.x86_64 需要
	perl(Getopt::Long) 被 mysql-community-server-5.7.34-1.el7.x86_64 需要
	perl(strict) 被 mysql-community-server-5.7.34-1.el7.x86_64 需要

出现错误解决方式:
很简单,如错误信息显示,缺少net-tools.x86_64,libaio.x86_64,perl.x86_64三个依赖,使用yum安装即可

查询依赖对应包
yum search perl
yum search libaio 
yum search net-tools

yum安装对应包
yum -y install perl.x86_64
yum install -y libaio.x86_64
yum -y install net-tools.x86_64

6.启动MySQL💎🍭

[root@oldgirl mysql]# systemctl start mysqld

①.❤️查看MySQL初始密码

[root@oldgirl mysql]# cat /var/log/mysqld.log | grep password
2021-10-09T05:44:11.704015Z 1 [Note] A temporary password is generated for root@localhost: lVBc<q8;r45C

②.❤️登录MySQL

[root@oldgirl mysql]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.34

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

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> 
退出mysql修改密码(因为初始密码太难记了)
mysql> exit
Bye
[root@oldgirl mysql]# vi /etc/my.cnf

# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html

[mysqld]
validate_password=off   //添加这个,然后保存退出

# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock

# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
:wq   

④.❤️重启MySQL

[root@oldgirl mysql]# systemctl restart mysqld
[root@oldgirl mysql]# 

⑤.❤️重新登录MySQL并修改密码

[root@oldgirl mysql]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.34

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

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> alter user 'root'@'localhost' identified by'root1';   //这行是修改密码为root1
Query OK, 0 rows affected (0.00 sec)

7.大功告成⭐⭐⭐⭐🔥🔥🔥🔥🔥

[root@oldgirl mysql]# mysql -uroot -p
Enter password:    //输入密码root就登录进来了
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.34 MySQL Community Server (GPL)

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

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> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.00 sec)

mysql> 

看完文章后,简单吧?估计你全学会了,加油,开始学习你的MySQL!!
请添加图片描述

给你7个棒棒糖🍭🍭🍭🍭🍭🍭🍭

觉得文章可以,果断❤️点赞❤️收藏❤️关注❤️

粉丝专属福利

🍓学习资料含C/C++、算法、Mysql、Linux、后端等。
🍓行业资料关注即可领取PPT模板、简历模板、行业经典书籍PDF。
🍓面试题库由技术群里的小伙伴们共同投稿,热乎的大厂面试真题,持续更新中。
🍓交流加群大佬指点迷津,你的问题往往有人遇到过,求资源在群里喊一声。

👇👇👇👇👇👇👇
请添加图片描述
💌 欢迎大家在评论区提出意见和建议!💌

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

Linux小魔王

谢谢鼓励。

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

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

打赏作者

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

抵扣说明:

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

余额充值