当前位置:网站首页>玩转Linux,轻松安装配置MySQL
玩转Linux,轻松安装配置MySQL
2022-06-26 16:46:00 【小勾】
本文主要讲解在Linux上安装、配置和使用MySQL,文中使用的Linux系统为CentOS7.6版本
最近壹哥购买了一个虚拟主机,但是壹哥很穷,所以只买了一个单纯的虚拟主机,里面除了一个CentOS系统之外,真的是啥也没有了。但壹哥还必须要用MySQL,所以就只能在这个CentOS中自己手动安装MySQL了,于是壹哥就把自己安装MySQL的过程记录了下来,供大家参考。
一、 基于Linux系统的MySQL安装
本文主要讲解手动安装MySQL,没有使用傻瓜式的Docker,那个太简单了......
1.1 使用wget指令下载MySQL的rpm包
安装MySQL之前,肯定要现有MySQL的安装包,这里壹哥使用wget来进行下载。
在Linux系统创建并进入指定的目录,以下为 /usr/local目录,使用pwd指令查看当前目录的路径,然后通过wget指令现在mysql的rpm包,此处下载的mysql版本为 5.7。
[[email protected] local]# pwd/usr/local[[email protected] local]# wget http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm1.2 通过rpm安装MySQL
MySQL下载之后,利用rpm进行安装。
通过rpm指令安装下载的rpm包
[[email protected] local]# rpm -ivh mysql57-community-release-el7-10.noarch.rpm1.3 通过yum安装mysql服务
接下来我们还要开启mysql服务。
MySQL是作为一个服务在系统运行的,安装rpm包之后通过yum指令安装MySQL服务
[[email protected] local]# yum -y install mysql-community-server安装mysql服务的过程中,你可能是遇到如下错误:

如果出现上述安装错误,表示安装过程中的GPG验证不通过,我们可以在yum指令后添加
--nogpgcheck选项 重新执行安装:
[[email protected] local]# yum -y install mysql-community-server --nogpgcheck二、MySQL服务管理
MySQL软件安装好之后,我们还需要对MySQL进行一些必要的配置,以下是配置mysql服务时的常用命令。
2.1 将MySQL服务加入开机启动
添加mysql开机启动之后,MySQL服务会伴随系统启动而启动。
[[email protected] local]# systemctl enable mysqld2.2 启动MySQL服务
在CentOS7中可以使用systemctl进行服务管理,如果你使用的Linux系统版本不支持systemctl,也可以使用service mysqld start来启动MySQL服务。
[[email protected] local]# systemctl start mysqld [[email protected] local]# lsof -i:3306COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAMEmysqld 8430 mysql 17u IPv6 70095 0t0 TCP *:mysql (LISTEN)2.3 停止MySQL服务
[[email protected] local]# systemctl stop mysqld或者使用:
[[email protected] local]# service mysqld stop三、MySQL基本使用
接下来我们就可以使用MySQL了。
3.1 查找MySQL初始密码
MySQL服务启动之后,我们可以通过mysql指令启动MySQL客户端连接MySQL数据库,连接需要root帐号密码,在安装MySQL的过程中默认生成了root帐号的初始密码记录在 /var/log/mysqld.log文件中,通过cat指令可以查询初识密码,执行指令如下:
[[email protected] local]# cat /var/log/mysqld.log | grep password如下图执行结果的空色框中即为初识密码

3.2 使用初始密码登录MySQL
执行mysql指令,-u选项后的root表示用户名,-p选项后不加参数直接回车,然后输入初始密码(输入密码时在输入框没有反馈,输入完成之后直接回车即可),出现mysql>执行提示,表示登录成功。

3.3 修改MySQL初始密码
初始密码只用于登录,登录之后必须修改初始密码才可以进行数据库操作;由于MySQL具有密码的安全性校验,所以可以先设置密码验证策略为LOW,再进行密码设置,如下:
特别说明:密码的设置是在mysql客户端输入的sql命令
# 设置密码的检查机制为LOWmysql> set global validate_password_policy=LOW;# 修改密码mysql> set password=password('admin123');3.4 授权root用户允许远程登录
密码修改完成之后,执行exit指令,退出mysql客户端,然后使用修改后的密码重新登录

登录之后,root用户默认是不支持远程连接的,如果要使用远程客户端(Navicat、SQLYog等)root账号连接MySQL数据库进行授权,授权时可以指定root账号远程连接的密码(如下指令密码为 admin123)
mysql> GRANT ALL PRIVILEGES on *.* to 'root'@'%' IDENTIFIED by 'admin123' WITH GRANT OPTION;mysql> flush PRIVILEGES;以上两条指令完成之后,你可以尝试使用navicat连接MySQL数据库啦!
PS:如果使用的云服务器的Linux系统,还要注意安全组配置放行3306端口哟~
现在你知道怎么在CentOS中安装配置以及使用MySQL了吗?如果还有疑问,可以评论区给壹哥留言,我来给你解决。
边栏推荐
- Leetcode 1169. 查询无效交易(如果数据量不大,这种题还是得暴力枚举解决)
- She said she was tired! So tired! I want to change my career
- Over the weekend: 20000 words! Summary of JVM core knowledge, 18 serial cannons as a gift
- Research on natural transition dubbing processing scheme based on MATLAB
- JS tutorial - printing stickers / labels using the electronjs desktop application
- [chat in 5] eight years after graduation, I have been pursuing my dream
- Web3 decentralized storage ecological landscape
- 建立自己的网站(16)
- 探讨:下一代稳定币
- Vibrating liquid quantity detecting device
猜你喜欢

经典同步问题

20:第三章:开发通行证服务:3:在程序中,打通redis服务器;(仅仅是打通redis服务器,不涉及具体的业务开发)

5G未平6G再启,中国引领无线通信,6G的最大优势在哪里?

Leetcode 1170. Frequency of occurrence of the minimum letter of the comparison string (yes, solved)
![[graduation season] a word for graduates: the sky is high enough for birds to fly, and the sea is wide enough for fish to leap](/img/b6/21e51fa7f79d4a4b950f061703f0fb.png)
[graduation season] a word for graduates: the sky is high enough for birds to fly, and the sea is wide enough for fish to leap
Teach you to learn dapr - 6 Publish subscription

Research on natural transition dubbing processing scheme based on MATLAB

防火 疏散 自救…这场安全生产暨消防培训干货满满!

Deployment and operation of mongodb partitioned cluster

Kubecon China 2021 Alibaba cloud special session is coming! These first day highlights should not be missed
随机推荐
Use the array to calculate the average of N numbers, and output the numbers greater than the average
Fgetc() reads content from file
C language -- legal identifier and integer
Programmer interview guide - self introduction
[从零开始学习FPGA编程-46]:视野篇 - 集成电路的发展与技术进步
What does the equals method compare? Who told you
Count the number of words in a line of string and take it as the return value of the function
A simple membership card management system based on Scala
STM32F103C8T6实现呼吸灯代码
数字藏品与NFT到底有何区别
Greenplum database fault analysis - semop (id=2000421076, num=11) failed: invalid argument
Apache APIs IX has the risk of rewriting the x-real-ip header (cve-2022-24112)
Redis overview
Leetcode 1169. 查询无效交易(如果数据量不大,这种题还是得暴力枚举解决)
Discover K8E: minimalist kubernetes distribution
Memory partition model
Calculate the average of N numbers in the group indexed by the formal parameter x, move the data less than the average in the group indexed to the front of the array, and move the data greater than or
[graduation season] a word for graduates: the sky is high enough for birds to fly, and the sea is wide enough for fish to leap
[Li Kou brush questions] 11 Container holding the most water //42 Rain water connection
JS tutorial - printing stickers / labels using the electronjs desktop application