安装MySQL数据库
安装 MySQL Repository
1、默认 yum 存储库安装
[root@qfedu.com~]#yum-yinstallwget#安装wget下载工具
[root@qfedu
.com~]#wgethttps://repo.mysql.com/mysql57-community-release-el7-
11.noarch.rpm#
下载mysql官方yum源安装包
[root@qfedu.com~]#yu
m-ylocalinstallmysql57-community-release-el7-
11.noarch.rpm#安装mysql官方yu
m源
2、选择指定发行版本安装
使用 MySQL Yum 存储库时,默认情况下会选择要安装的最新GA版本MySQL。默认启用最新GA 系列(当前为MySQL 8.0)的子存储库,而所有其他系列(例如,MySQL 5.7系列)的子存储库均 被禁用。查看已启用或禁用了存储库。
1)列出所有版本
[root@qfedu.com~]#yumrepolistall|grepmysql
发现启用最新8.0版本是 enabled 的,5.7版本是 disabled 的,需要安装5.7版本时,所以把8.0的进行禁用,然后再启用5.7版本
2)安装 yum 配置工具
[root@qfedu.com~]#yum-yinstallyum-utils
3)禁用 8.0 版本
[root@qfedu.com~]#yum-config-manager--disablemysql80-community
4)启用 5.7 版本
[root@qfedu.com~]#yum-config-manager--enablemysql57-community
5)检查启用版本
注意:进行安装时请确保只有一个版本启用,否则会显示版本冲突
[root@qfedu.com~]#yumrepolistenabled|grepmysql
安装 MySQL
需要安装MySQL Server, MySQL client 已经包括在 server 套件内
[root@qfedu.com~]#yum-yinstallmysql-community-servermysql#安装服务
端,客户端
[root
@qfedu
.com~]#systemctlstartmysqld#启动mysql
服务
[root@qfedu.com
~]#
systemctlenablemysqld#设置mysql
服务开机启动
[root@qfedu.com~]#ls/var/lib/m
ysql#查看
mysql
安装
[root@qfedu.com~]#grep'tqfeduorarypassword'/var/lo
g/m
ysqld.log#获取首次登
录密码
[root@qfedu.com~]#mysql-uroot-p'awm3>!QFl6zR'#登录mysql
数据
库
my
sql>alteruser'root'@'localhost'identifiedby'Qf.123com';#修改mysql
数据库密
码(密码
必须符合复杂性要求,包含字母大小写,数字,特赦符号,长度不少于8位)
[root@qfedu.com~]#mysql-uroot-p'Qf.123com'#用新
密码登
录数据库
重启 MySQL
[root@qfedu.com~]#systemctlrestartmysqld
创建 qfedu 库并设置权限
[root@qfedu.com~]#mysql-uroot-p
Ente
rpassword:
Welco
metotheMySQLmonitor.Commandsendwith;or\g.
YourMySQLconnec
tionidis3
Serverversion:5.6.39
MySQLCommunityServer(GPL)
Copyright(c)2000,2018,Orac
leand/oritsaffiliates.Allrightsreserved.
OracleisaregisteredtrademarkofOracle
Corporationand/orits
affiliates.Othernamesmaybetrademarksoftheirre
spective
owners.
Type'help;'or'\h'forhelp.Type'\c'toclearthecu
rrentinp
utstatement.
mysql>CRE
ATE
DATABASEqfedudbCHARACTERSETutf8COLLATEutf8_bin;
QueryO
K,1rowaffected(0.00sec)
mysql>GRANTSELECT,INSERT,UPDATE,DELETE,CREA
TE,DROP,ALTER,INDEXonqfedudb.*TO
'qf
edu'@'localhost'IDENTIFIEDBY'Yangge.123com';
QueryOK,0rowsaffected,1warning(0.00
sec)
mysql>FLUSHPRIVILEGES;
QueryOK,0rowsaffected(0
.00sec)
mysql>SHOWGRANTSFOR'qfedu'@'localhost';
+------------------------
-------------------------------------
------------------
-------------------------
-----+
|Grantsforqfedu@localhost
|
+---------------------------------------------
--------------------------------
--
-------
---
--------------------+
|GRANTUSAGEON*.*TO'qfedu'@'localhost'IDENTIFIE
DBYPASSWORD
'*841E9705B9F4BD3195
B7314CA58A7E3B3B349F71'|
|GRANTSELECT,INSERT,UPDATE,DELETE,CREATE,DROP,INDEX,ALTE
RON
`qfedudb`.*TO'qfedu'@'localh
ost'|
+------------------------------------------------------------
-------------------
--------------------------
----+
2rowsinset(0.00sec)
mysql>SHOWGRANTSFOR'qfedu'@'172.16.0.122';
+
-------------------------------------------
------------------------------------
---------------------------------+
|Grantsfo
rqfedu@172.16.0.122
|
+---------
--------
--
---------------
---------------------------------------------
-
--------------------------------+
|GRANTUSAGEON*.*TO'qfedu'@'172.16.0.122'IDENTIF
IEDBYPASSWORD
'*841E9705B9F4BD3195B
7314CA58A7
E3B
3B349F71'|
|GRANTSE
LE
CT,INSERT,UPDATE,DELETE,CREATE,DROP,INDEX,ALTERON
`qfedudb`.*TO'qfedu'@'172.16.0.
122'|
+----------------------------
---------------------------------------------------
------------------
---------------+
2rowsinset(0.01sec)
mysql>\q
Bye