Centos下MySQL(Mariadb)的安装

本文详细介绍了在Centos系统中安装MySQL和MariaDB数据库的过程,包括使用yum安装MariaDB,从官网下载MySQL安装包,以及如何启动数据库服务和登录数据库。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

  • Mariadb的安装

因为Centos默认的数据库是Mariadb,所以安装很简单,只需要使用yum安装即可。

[root@bogon ~]# yum -y install mariadb-server mariadb
[root@bogon ~]# rpm -qi mariadb   #查看是否安装成功

解释:mariadb只是client客户端,mariadb-server才是mariadb的后台数据库。

还有一点,在Centos中,执行yum -y install mysql mysql-server其实安装的是mariadb。

启动mariadb并加入开机自启

[root@bogon ~]# systemctl start mariadb
[root@bogon ~]# systemctl enable mariadb
Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.
[root@bogon ~]# 

登录mariadb。

首次安装,mariadb的密码默认为空,所以输密码时直接敲回车就行。还有一点要注意:mariadb的命令和mysql的命令几乎一模一样。

[root@bogon ~]# mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 9
Server version: 5.5.60-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> 

  • MySQL的安装

首先查看是否安装了mariadb

[root@bogon ~]# rpm -q mariadb
mariadb-5.5.60-1.el7_5.x86_64
[root@bogon ~]# 

若安装了,卸载掉

[root@bogon ~]# rpm -q mariadb

接下来安装MySQL

因为Centos默认的数据库是mariadb,所以yum源里是没有安装包的,要去官网上下载。

链接:

https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm

[root@bogon ~]# wget  https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm

安装MySQL的rpm包

[root@bogon ~]# rpm -ivh mysql57-community-release-el7-11.noarch.rpm 

查看是否安装成功

[root@bogon ~]# rpm -q mysql57-community-release 
mysql57-community-release-el7-11.noarch

安装MySQL

[root@bogon ~]# yum -y install mysql-server

现在执行这条命令安装的才是MySQL,不是mariadb

启动MySQL并加入开机自启

[root@localhost ~]# systemctl start mysqld
[root@localhost ~]# systemctl enabl mysqld

登录MySQL。和mariadb一样,首次登录密码默认为空

[root@localhost ~]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.24 MySQL Community Server (GPL)

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

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> 

ok,MySQL|mariadb的安装就完成了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

afei00123

您的支持是我创作最大的动力

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

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

打赏作者

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

抵扣说明:

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

余额充值