centos7安装es mysql_Centos7.6安装mysql

这篇博客详细介绍了如何在CentOS系统中卸载默认的MariaDB并安装MySQL,包括下载Yum Repository,安装MySQL服务器,启动和检查MySQL状态,设置开机启动,查找并修改初始密码。此外,还讲解了如何允许root用户远程登录MySQL,这对于开发工作非常有用。
摘要由CSDN通过智能技术生成

在CentOS中默认安装有MariaDB,而我们需要用的mysql,所有需要将其覆盖掉,下面是安装过程:

1、下载并安装MySQL官方的 Yum Repository

[root@VM-0-7-centos ~]# wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm

2、安装MySQL服务器。

[root@VM-0-7-centos ~]# yum -y install mysql57-community-release-el7-10.noarch.rpm[root@VM-0-7-centos ~]# yum -y install mysql-community-server

出现如下图所示,则表示安装成功:

27529f5cf0b019d24192903123f9f89b.png

3、首次启动mysql

[root@VM-0-7-centos ~]# systemctl start  mysqld.service

4、查看mysql运行状态

[root@VM-0-7-centos ~]# systemctl status mysqld.service

8a269abea8c523c1d1ac27c5d778b62a.png

5、设置开机自启动

[root@VM-0-7-centos ~]# systemctl enable mysqld

6、卸载Yum Repository

       但此时还有一个问题,就是因为安装了Yum Repository,以后每次yum操作都会自动更新,需要把这个卸载掉:

[root@VM-0-7-centos ~]# yum -y remove mysql57-community-release-el7-10.noarch

至此,mysql的安装已经全部完毕,下面进行mysql的一些操作。

1、获取mysql初始密码

安装好mysql之后,输入mysql就可以进入mysql,但是mysql默认帮我设置了初始密码,导致我们进不去,如下图所示

9d1b0f432e8ce56d653c5086ed18833b.png

此时,我们可以查看mysql安装的日志,找到初始密码,如下图所示:

[root@VM-0-7-centos ~]# cat /var/log/mysqld.log

或者通过grep快速找到初始密码,如下所示

[root@VM-0-7-centos ~]# cat /var/log/mysqld.log |grep "password"2021-01-03T07:58:49.809313Z 1 [Note] A temporary password is generated for root@localhost: D.hV:nDQi3RU2021-01-03T08:05:40.815394Z 2 [Note] Access denied for user 'root'@'localhost' (using password: NO)2021-01-03T08:14:45.549773Z 3 [Note] Access denied for user 'root'@'localhost' (using password: NO)

2、进入mysql

输入mysql -u root -p 后再输入初始密码即可进入mysql,如下图所示,接下就可以创建数据库、创建表等一系列操作了。

[root@VM-0-7-centos ~]# mysql -u root -pEnter password:Welcome to the MySQL monitor.  Commands end with ; or \g.Your MySQL connection id is 12Server version: 5.7.32Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql>

3、退出mysql

mysql> exit;Bye[root@VM-0-7-centos ~]#

4、进入mysql修改密码

输入mysql -u root -p 后再输入初始密码即可进入mysql,输入

 set password for root @localhost = password('ABCDabcd1234.?')

即可修改密码为ABCDabcd1234.?,如下图所示

[root@VM-0-7-centos ~]# mysql -u root -pEnter password:Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql>  set password for root @localhost = password('ABCDabcd1234.?');Query OK, 0 rows affected, 1 warning (0.00 sec)mysql> exit;Bye

5、配置mysql的root用户允许远程登录

     基于安全考虑root账户一般只能本地访问(新安装的数据库只能localhost访问),但是在开发过程中可能需要打开root的远程访问权限。下面是基本的步骤:

(1)输入mysql -u root -p 然后在输入密码即可进入mysql,然后再输入如下命令:

mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'ABCDabcd1234.?' WITH GRANT OPTION;mysql> flush privileges;

其中"*.*"代表所有资源所有权限, “'root'@%”其中root代表账户名,%代表所有的访问地址,也可以使用一个唯一的地址进行替换,只有一个地址能够访问。如果是某个网段的可以使用地址与%结合的方式,如10.0.42.%。IDENTIFIED BY 'root',这个ABCDabcd1234.?是指访问密码。WITH GRANT OPTION允许级联授权。

flush privileges;表示刷新访问权限表

(2)使用navicat远程连接

111553648aca3a4a1bc8575997cf9845.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值