Linux系列 CentOS7(yum)安装mysql5.7

前言

本文详细讲述了mysql5.7使用yum安装的方式安装,最后也会进行基础的安全配置,可以根据自身情况进行配置,最好不要太难哦,有问题可以评论区留言!

步骤一:安装MySQL5.7

更新yum源

安装之前我们需要先更新一下yum源

rpm -Uvh  http://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm

yum方式下载安装mysql

yum -y install mysql-community-server

查看下载的mysql版本号

mysql -V

返回结果如下,表示MySQL安装成功。

mysql  Ver 14.14 Distrib 5.7.31, for Linux (x86_64) using  EditLine wrapper

步骤二:启动MySQL

启动MySQL服务

systemctl start mysqld

设置MySQL服务开机自启动。

systemctl enable mysqld

获取并记录root用户的初始密码。

grep 'temporary password' /var/log/mysqld.log

执行命令结果示例如下。

2020-04-08T08:12:07.893939Z 1 [Note] A temporary password is generated for root@localhost: xvlo1lZs7>uI

说明 下一步对MySQL进行安全性配置时,会使用该初始密码。

步骤三:配置MySQL

安全性配置命令

mysql_secure_installation

通过这个命令我们可以进行一些常用的安全设置,建议生产环境中mysql安装完以后一定要运行一次mysql_secure_installation,运行完以后按需配置即可!

重置root用户的密码。

Enter password for user root: #输入上一步获取的root用户初始密码
The 'validate_password' plugin is installed on the server.
The subsequent steps will run with the existing configuration of the plugin.
Using existing password for root.
Estimated strength of the password: 100
Change the password for root ? ((Press y|Y for Yes, any other key for No) : Y #是否更改root用户密码,输入Y
New password: #输入新密码,长度为8至30个字符,必须同时包含大小写英文字母、数字和特殊符号。特殊符号可以是()` ~!@#$%^&*-+=|{}[]:;‘<>,.?/
Re-enter new password: #再次输入新密码
Estimated strength of the password: 100
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : Y #是否继续操作,输入Y

删除匿名用户账号。

By default, a MySQL installation has an anonymous user, allowing anyone to log into MySQL without having to have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment.
Remove anonymous users? (Press y|Y for Yes, any other key for No) : Y  #是否删除匿名用户,输入Y
Success.

安装完MySQL以后系统会自动创建一个root用户和一个匿名用户,对于root大家都非常注意,而这个匿名用户很多人都会忽略,大概是因为匿名用户默认设定为只能在本地使用的缘故吧,但如果MySQL要作为数据库提供给Web服务器使用的话,忽略这个匿名用户的代价可能相当惨重。因为在默认设置下,这个匿名用户在localhost上几乎拥有和root一样的权限。很可能因为访问者上传一个PHP文件,用这个PHP文件创建一个新用户,并给他一个较高的权限,然后用这个新用户连接到服务器的MySQL,对该服务器的MySQL进行管理

禁止root账号远程登录。

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : Y #禁止root远程登录,输入Y
Success.

一般开发环境的话,root用户都是禁止远程登录,root账户一旦泄露也只能先登录你的服务器才能对mysql操作

删除test库以及对test库的访问权限。

Remove test database and access to it? (Press y|Y for Yes, any other key for No) : Y #是否删除test库和对它的访问权限,输入Y
- Dropping test database...
Success.

重新加载授权表。

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : Y #是否重新加载授权表,输入Y
Success.
All done!

安全性配置的更多详情,小伙伴们可以参见一下MySQL官方文档\~\~\~

步骤四:远程访问MySQL数据库

您可以使用数据库客户端来远程访问MySQL数据库,我一般用的是Navicat,小沐恩福利(博客左侧栏分享的阿里云盘共享文件夹有Navicat15破解版哦)其实还有一个小海豚sqlyong也挺好用的小伙伴也可以尝试一下,不过现在sqlyong也要花钱了哎...

登录mysql

mysql -uroot -p

创建远程登录MySQL的账号

示例账号为test、密码为123456

mysql> grant all on *.* to 'test'@'%' IDENTIFIED BY '123456'; #注意 :使用root替换test,可设置为允许root账号远程登录。
mysql> flush privileges;

然后就可以使用设置的账号密码登录 mysql 喽

暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
下一篇