centos7 安装 mysql

 mysql 安装

话不多说, 以下三条指令梭哈一下.

yum install mysql
yum install mysql-server
yum install mysql-devel

安装 mysql  和 mysql-devel 都安装成功, 但是安装mysql-server失败, 错误消息如下:

[root@yl-web yl]# yum install mysql-server
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.sina.cn
 * extras: mirrors.sina.cn
 * updates: mirrors.sina.cn
No package mysql-server available.
Error: Nothing to do

centos7 将 mysql-server 从默认软件列表中移除掉了, 用mariadb代替了

一、安装mariadb

MariaDB数据库管理系统是MySQL的一个分支,主要由开源社区在维护,采用GPL授权许可。开发这个分支的原因之一是:甲骨文公司收购了MySQL后,有将MySQL闭源的潜在风险,因此社区采用分支的方式来避开这个风险。MariaDB的目的是完全兼容MySQL,包括API和命令行,使之能轻松成为MySQL的代替品。

安装mariadb

 yum install mariadb-server mariadb 

mariadb数据库的相关命令是:

systemctl start mariadb  #启动MariaDB

systemctl stop mariadb  #停止MariaDB

systemctl restart mariadb  #重启MariaDB

systemctl enable mariadb  #设置开机启动

先启动数据库

systemctl start mariadb

二、安装 mysql

1. 下载安装 mysql 官方的 yum repository

wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm

然后就可以直接安装

yum -y install mysql57-community-release-el7-10.noarch.rpm

再安装 mysql 服务器

yum -y install mysql-community-server

mariadb数据库的相关命令是:

systemctl start mysqld.service #启动MariaDB

systemctl stop mysqld.service #停止MariaDB

systemctl restart mysqld.service #重启MariaDB

systemctl enable mysqld.service #设置开机启动

先启动数据库

systemctl start mysqld.service

三、配置mysql

输入命令

mysql_secure_installation

 设定密码

[root@localhost ~]#  mysql_secure_installation

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

**这里是设定当前mysql的root用户的密码,这个时候,密码还是空,所以直接回车就行了。

Enter current password for root (enter for none): 
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n] y
** 设定 root 的密码

移除默认的匿名账户

By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB 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? [Y/n] Y
 ... Success!

禁止远程连接

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] n
 ... skipping.

 删除默认的test 数据库

By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] n
 ... skipping.

重新加载刚才的配置

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] Y
 ... Success!

到这里配置就完成了

启动服务

sudo systemctl start mariadb

关闭服务

sudo systemctl stop mariadb

查看服务状态

sudo systemctl status mariadb

设置自启动

sudo systemctl enable mariadb

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值