6步在CentOS安装和配置MariaDB MySQL

简介:

MariaDB MySQL软件包

以下是三个主要的MariaDB包:

  • mariadb-5.5.52-1.el7.x86_64 - 这包含几个MySQL客户端程序和实用程序。

  • mariadb-server-5.5.52-1.el7.x86_64 - 这是主要的MariaDB MySQL数据库服务器。

  • mariadb-libs-5.5.52-1.el7.x86_64 - 包含客户机程序界面所需的共享库。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# yum info mariadb-server
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
  * base: repos-va.psychz.net
  * extras: linux.cc.lehigh.edu
  * updates: mirror.us.leaseweb.net
Available Packages
Name        : mariadb-server
Arch        : x86_64
Epoch       : 1
Version     : 5.5.52
Release     : 1.el7
Size        : 11 M
Repo        : base /7/x86_64

2.安装MariaDB MySQL服务器

使用yum install安装如下所示的MariaDB MySQL服务器软件包。

1
#yum  install  mariadb-server

此时,在这个服务器上,已经安装了mariadb-server以及以下依赖的包。

1
2
3
4
5
6
7
8
9
10
11
12
mariadb-server.x86_64 1:5.5.52-1.el7
mariadb-libs.x86_64 1:5.5.52-1.el7
mariadb.x86_64 1:5.5.52-1.el7
libaio.x86_64 0:0.3.109-13.el7
perl-DBD-MySQL.x86_64 0:4.023-5.el7
perl-DBI.x86_64 0:1.627-4.el7
perl-Compress-Raw-Bzip2.x86_64 0:2.061-3.el7
perl-Compress-Raw-Zlib.x86_64 1:2.061-4.el7
perl-Data-Dumper.x86_64 0:2.145-3.el7
perl-IO-Compress.noarch 0:2.061-2.el7
perl-Net-Daemon.noarch 0:0.48-5.el7
perl-plRPC.noarch 0:0.2020-14.el7

验证确保这已经安装了三个重要的MariaDB mysql包。

1
2
3
4
#rpm -qa |  grep  -i maria 
mariadb-5.5.52-1.el7.x86_64 
mariadb-server-5.5.52-1.el7.x86_64 
mariadb-libs-5.5.52-1.el7.x86_64

3.启动MariaDB数据库

如下所示,mariadb数据库服务器模块已加载,但尚未启动。

1
2
3
4
# systemctl status mariadb
? mariadb.service - MariaDB database server
    Loaded: loaded ( /usr/lib/systemd/system/mariadb .service; disabled; vendor preset: disabled)
    Active: inactive (dead)

使用systemctl启动MariaDB mysql服务器,如下:

1
#systemctl start mariadb

验证systemctl状态以确保mariadb数据库服务器已成功启动

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# systemctl status mariadb
? mariadb.service - MariaDB database server
    Loaded: loaded ( /usr/lib/systemd/system/mariadb .service; disabled; vendor preset: disabled)
    Active: active (running) since Thu 2017-06-26 18:26:35 UTC; 13s ago
   Process: 4049 ExecStartPost= /usr/libexec/mariadb-wait-ready  $MAINPID (code=exited, status=0 /SUCCESS )
   Process: 3969 ExecStartPre= /usr/libexec/mariadb-prepare-db-dir  %n (code=exited, status=0 /SUCCESS )
  Main PID: 4048 (mysqld_safe)
    CGroup:  /system .slice /mariadb .service
            +-4048  /bin/sh  /usr/bin/mysqld_safe  --basedir= /usr
            +-4206  /usr/libexec/mysqld  --basedir= /usr  --datadir= /var/lib/mysql  --plugin- dir = /usr/lib64/mysql/plugin  --log-error= /var/log/mariadb/ma ...
 
Aug 15 15:20:30 deploy mariadb-prepare-db- dir [3969]: The latest information about MariaDB is available at http: //mariadb .org/.
Aug 15 15:20:30 deploy mariadb-prepare-db- dir [3969]: You can  find  additional information about the MySQL part at:
Aug 15 15:20:30 deploy mariadb-prepare-db- dir [3969]: http: //dev .mysql.com
Aug 15 15:20:30 deploy mariadb-prepare-db- dir [3969]: Support MariaDB development by buying support /new  features from MariaDB
Aug 15 15:20:30 deploy mariadb-prepare-db- dir [3969]: Corporation Ab. You can contact us about this at sales@mariadb.com.
Aug 15 15:20:30 deploy mariadb-prepare-db- dir [3969]: Alternatively consider joining our community based development effort:
Aug 15 15:20:30 deploy mariadb-prepare-db- dir [3969]: http: //mariadb .com /kb/en/contributing-to-the-mariadb-project/
Aug 15 15:20:30 deploy mysqld_safe[4048]: 170601 15:20:33 mysqld_safe Logging to  '/var/log/mariadb/mariadb.log' .
Aug 15 15:20:30 deploy mysqld_safe[4048]: 170601 15:20:33 mysqld_safe Starting mysqld daemon with databases from  /var/lib/mysql
Aug 15 15:20:35 deploy systemd[1]: Started MariaDB database server.


4.连接并验证MariaDB Server

使用如下所示的mysql命令使用mysql的root用户连接到数据库

1
2
3
4
5
6
7
8
9
# mysql -u root
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection  id  is 2
Server version: 5.5.52-MariaDB MariaDB Server
  
Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.
  
Type  'help;'  or  '\h'  for  help. Type  '\c'  to  clear  the current input statement.
MariaDB [(none)]>


以下show database命令将显示默认的mysql数据库。

1
2
3
4
5
6
7
8
9
MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
test                |
+--------------------+


5.执行MariaDB Post Installation步骤

从上方可以看出,默认情况下,安装不会为MySQL root帐户分配任何密码。

要设置mysql root用户密码并在数据库上执行其他安全配置,请执行如下所示的mysql_secure_installation脚本。

1
2
3
4
5
6
7
8
9
# /usr/bin/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帐户分配密码。所以,请在这里输入

1
2
3
4
5
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.



在这个阶段,说“y”为MySQL根帐户分配密码。之后输入密码。

请注意,这个mysql root帐户与linux root帐户不同。所以,我们在这里设置mysql root帐号的密码,这与Linux root帐号无关。

1
2
3
4
5
6
Set root password? [Y /n ] y
New password: 
Re-enter new password: 
Password updated successfully!
Reloading privilege tables..
  ... Success!

作为默认安装的一部分,mysql安装匿名用户,无需真实用户即可登录数据库。所以我们应该删除这个用户

1
2
3
4
5
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.


可以想像,mysql root帐号将可以访问所有的mysql数据库。所以,保持这个安全是很重要的。此外,我们应该确保来自其他服务器的远程客户端不允许使用此mysql root帐户进行连接。

相反,只有本地主机(其中安装了mysql服务器)可以使用root帐户进行连接。所以我们应该远程禁止root登录。

1
2
Disallow root login remotely? [Y /n ] y
  ... Success!


这是默认的测试数据库,我们应该删除它。

1
2
3
4
5
Remove  test  database and access to it? [Y /n ] y
  - Dropping  test  database...
  ... Success!
  - Removing privileges on  test  database...
  ... Success!


在这里输入y,以确保我们所做的所有更改将立即生效。

1
2
3
4
5
6
7
8
9
Reload privilege tables now? [Y /n ] y
  ... Success!
  
Cleaning up...
  
All  done !  If you've completed all of the above steps, your MariaDB
installation should now be secure.
  
Thanks  for  using MariaDB


6.验证MySQL根访问

现在,如果您连接到没有root密码的Mysql,您将收到以下访问被拒绝的错误消息。

1
2
# mysql -u root
ERROR 1045 (28000): Access denied  for  user  'root' @ 'localhost'  (using password: NO)


要指定密码,请使用-p选项,如下所示。这将提示用户输入密码。

1
2
# mysql -u root -p
Enter password:

另外,从下面的show databases命令可以看出,测试数据库现在被删除了。

1
2
3
4
5
6
7
8
MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
+--------------------+

如果要在mysql命令行中传递密码,请在-p选项旁边指定,如下所示。


1
# mysql -u root -pMySecurePassword

注意:-p和密码之间没有空格。这可能会导致一些混淆,因为我们在-u和username之间有空格。但是,-p和密码之间没有空格。



本文转自 喵来个鱼 51CTO博客,原文链接:http://blog.51cto.com/m51cto/1958672,如需转载请自行联系原作者

相关实践学习
阿里云云原生数据仓库AnalyticDB MySQL版 使用教程
云原生数据仓库AnalyticDB MySQL版是一种支持高并发低延时查询的新一代云原生数据仓库,高度兼容MySQL协议以及SQL:92、SQL:99、SQL:2003标准,可以对海量数据进行即时的多维分析透视和业务探索,快速构建企业云上数据仓库。 了解产品 https://www.aliyun.com/product/ApsaraDB/ads
相关文章
|
2月前
|
Ubuntu 关系型数据库 MySQL
MySQL源码编译安装
本文详细介绍了MySQL 8.0及8.4版本的源码编译安装全过程,涵盖用户创建、依赖安装、cmake配置、编译优化等步骤,并提供支持多Linux发行版的一键安装脚本,适用于定制化数据库部署需求。
323 4
MySQL源码编译安装
|
2月前
|
Ubuntu 关系型数据库 MySQL
MySQL二进制包安装
本文详细介绍了在多种Linux系统上通过二进制包安装MySQL 8.0和8.4版本的完整过程,涵盖用户创建、glibc版本匹配、程序解压、环境变量配置、初始化数据库及服务启动等步骤,并提供支持多发行版的一键安装脚本,助力高效部署MySQL环境。
313 4
MySQL二进制包安装
|
2月前
|
安全 关系型数据库 MySQL
MySQL包安装 -- SUSE系列(离线RPM包安装MySQL)
本文详细介绍在openSUSE系统上通过离线RPM包安装MySQL 8.0和8.4版本的完整步骤,包括下载地址、RPM包解压、GPG密钥导入、使用rpm或zypper命令安装及服务启动验证,涵盖初始密码获取与安全修改方法,适用于无网络环境下的MySQL部署。
404 3
MySQL包安装 -- SUSE系列(离线RPM包安装MySQL)
|
2月前
|
NoSQL 算法 Redis
【Docker】(3)学习Docker中 镜像与容器数据卷、映射关系!手把手带你安装 MySql主从同步 和 Redis三主三从集群!并且进行主从切换与扩容操作,还有分析 哈希分区 等知识点!
Union文件系统(UnionFS)是一种**分层、轻量级并且高性能的文件系统**,它支持对文件系统的修改作为一次提交来一层层的叠加,同时可以将不同目录挂载到同一个虚拟文件系统下(unite several directories into a single virtual filesystem) Union 文件系统是 Docker 镜像的基础。 镜像可以通过分层来进行继承,基于基础镜像(没有父镜像),可以制作各种具体的应用镜像。
502 5
|
3月前
|
缓存 关系型数据库 BI
使用MYSQL Report分析数据库性能(下)
使用MYSQL Report分析数据库性能
163 3
|
3月前
|
关系型数据库 MySQL 数据库
自建数据库如何迁移至RDS MySQL实例
数据库迁移是一项复杂且耗时的工程,需考虑数据安全、完整性及业务中断影响。使用阿里云数据传输服务DTS,可快速、平滑完成迁移任务,将应用停机时间降至分钟级。您还可通过全量备份自建数据库并恢复至RDS MySQL实例,实现间接迁移上云。
|
3月前
|
关系型数据库 MySQL 数据库
阿里云数据库RDS费用价格:MySQL、SQL Server、PostgreSQL和MariaDB引擎收费标准
阿里云RDS数据库支持MySQL、SQL Server、PostgreSQL、MariaDB,多种引擎优惠上线!MySQL倚天版88元/年,SQL Server 2核4G仅299元/年,PostgreSQL 227元/年起。高可用、可弹性伸缩,安全稳定。详情见官网活动页。
800 152
|
4月前
|
存储 运维 关系型数据库
从MySQL到云数据库,数据库迁移真的有必要吗?
本文探讨了企业在业务增长背景下,是否应从 MySQL 迁移至云数据库的决策问题。分析了 MySQL 的优势与瓶颈,对比了云数据库在存储计算分离、自动化运维、多负载支持等方面的优势,并提出判断迁移必要性的五个关键问题及实施路径,帮助企业理性决策并落地迁移方案。
|
3月前
|
关系型数据库 MySQL 分布式数据库
阿里云PolarDB云原生数据库收费价格:MySQL和PostgreSQL详细介绍
阿里云PolarDB兼容MySQL、PostgreSQL及Oracle语法,支持集中式与分布式架构。标准版2核4G年费1116元起,企业版最高性能达4核16G,支持HTAP与多级高可用,广泛应用于金融、政务、互联网等领域,TCO成本降低50%。
|
3月前
|
关系型数据库 分布式数据库 数据库
阿里云数据库收费价格:MySQL、PostgreSQL、SQL Server和MariaDB引擎费用整理
阿里云数据库提供多种类型,包括关系型与NoSQL,主流如PolarDB、RDS MySQL/PostgreSQL、Redis等。价格低至21元/月起,支持按需付费与优惠套餐,适用于各类应用场景。