CentOS 7 部署 MariaDB 的 2 种方法

这篇具有很好参考价值的文章主要介绍了CentOS 7 部署 MariaDB 的 2 种方法。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

有两种安装 MariaDB 服务器的方法。您可以安装 CentOS 7 存储库中可用的默认版本,也可以通过手动添加 MariaDB 存储库来安装最新版本。

如果安装过MariaDB或MySQL,使用以下命令彻底删除它们:

yum remove mariadb*
yum remove mysql*

方法一: 使用 Yum安装 MariaDB

CentOS 存储库中 MariaDB 的默认版本是 MariaDB 5.5。虽然不是最新版本,但它非常稳定,强烈推荐。

要在 CentOS 7 上安装 MariaDB 5.5,请登录到您的服务器实例并使用 yum 包管理器。

1.1 安装 MariaDB

[root@ip-172-31-2-24 ~]# yum -y install mariadb
[root@ip-172-31-2-24 ~]# yum -y install mariadb-server

1.2 启动并配置MariaDB

[root@ip-172-31-2-24 ~]# systemctl start mariadb
[root@ip-172-31-2-24 ~]# systemctl status mariadb
[root@ip-172-31-2-24 ~]# systemctl enable mariadb
Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.

# 登录到MariaDB并设置root用户密码
[root@ip-172-31-2-24 ~]# /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.

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
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
 ... Success!

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.

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] Y
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

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

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!

1.3 检查 mariadb 状态

mysql -V

centos mariadb,MariaDB,centos,mariadb,linux

1.4 检查 MariaDB 版本

rpm -qi | grep mariadb

centos mariadb,MariaDB,centos,mariadb,linux

1.5 命令行查看 MariaDB 版本

mysql -u root -p

centos mariadb,MariaDB,centos,mariadb,linux

方法二: 从 Repo 安装 MariaDB

在编写本指南时,MariaDB 的最新版本是 MariaDB 10.4。

2.1 创建存储库文件

vi /etc/yum.repos.d/mariadb.repo

粘贴以下内容:

[mariadb]
name = MariaDB baseurl = http://yum.mariadb.org/10.4/centos7-amd64 gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB gpgcheck=1

2.2 更新 yum 缓存索引

yum makecache fast

2.3 安装 MariaDB 10.4:

yum install mariadb-server mariadb-client -y

2.4 启动 MariaDB 数据库

systemctl start mariadb
systemctl enable mariadb
systemctl status mariadb

# 查看MariaDB 版本
rpm -qi MariaDB-server

centos mariadb,MariaDB,centos,mariadb,linux

2.5 命令行访问 MariaDB 数据库

要以 root 用户身份访问 MariaDB 数据库,请调用以下命令:

mysql -u root -p

系统将提示您输入 sudo 密码,然后是 root 密码。

centos mariadb,MariaDB,centos,mariadb,linux

2.6 创建新用户并分配权限

# 只允许本地访问
MariaDB [(none)] >  create user 'linoxide'@'localhost' IDENTIFIED BY  'Password';
MariaDB [(none)] > GRANT ALL PRIVILEGES ON *.* TO 'linoxide'@'localhost';

# 允许远程访问
MariaDB [(none)] >  create user 'linoxide'@'%' IDENTIFIED BY  'Password';
MariaDB [(none)] > GRANT ALL PRIVILEGES ON *.* TO 'linoxide'@'%';

# 使用以下命令注销:
MariaDB [(none)] > quit;

# 使用新用户登录
mysql -u linoxide  -p

设置MariaDB字符集为utf-8

3.1 编辑/etc/my.cnf文件

在 [mysqld] 标签下添加
init_connect='SET collation_connection = utf8_unicode_ci'
init_connect='SET NAMES utf8'
character-set-server=utf8
collation-server=utf8_unicode_ci
skip-character-set-client-handshake

3.2 编辑/etc/my.cnf.d/client.cnf文件

[client] 标签下添加

default-character-set=utf8

3.3 编辑/etc/my.cnf.d/mysql-clients.cnf文件

[mysql] 标签下添加

default-character-set=utf8

3.4 重启服务

[root@mini ~]# systemctl restart mariadb

3.5 进入mariadb查看字符集

未配置字符集前

 MariaDB [(none)]> show variables like "%character%";show variables like "%collation%";
+--------------------------+----------------------------+
| Variable_name            | Value                      |
+--------------------------+----------------------------+
| character_set_client     | utf8                       |
| character_set_connection | utf8                       |
| character_set_database   | latin1                     |
| character_set_filesystem | binary                     |
| character_set_results    | utf8                       |
| character_set_server     | latin1                     |
| character_set_system     | utf8                       |
| character_sets_dir       | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.01 sec)

+----------------------+-------------------+
| Variable_name        | Value             |
+----------------------+-------------------+
| collation_connection | utf8_general_ci   |
| collation_database   | latin1_swedish_ci |
| collation_server     | latin1_swedish_ci |
+----------------------+-------------------+
3 rows in set (0.00 sec)

MariaDB [(none)]>

配置字符集后

MariaDB [(none)]> show variables like "%character%";show variables like "%collation%";
+--------------------------+----------------------------+
| Variable_name            | Value                      |
+--------------------------+----------------------------+
| character_set_client     | utf8                       |
| character_set_connection | utf8                       |
| character_set_database   | utf8                       |
| character_set_filesystem | binary                     |
| character_set_results    | utf8                       |
| character_set_server     | utf8                       |
| character_set_system     | utf8                       |
| character_sets_dir       | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.00 sec)

+----------------------+-----------------+
| Variable_name        | Value           |
+----------------------+-----------------+
| collation_connection | utf8_unicode_ci |
| collation_database   | utf8_unicode_ci |
| collation_server     | utf8_unicode_ci |
+----------------------+-----------------+
3 rows in set (0.00 sec)

MariaDB [(none)]>

远程链接MariaDB数据库

mariadb默认是拒绝 root 远程登录的。这里用的是 navicat 软件连接数据库。

4.1 查看mysql数据库中user表

[root@mini ~]# mysql -u root -p  # 先通过本地链接进入数据库
MariaDB [(none)]> use mysql;
MariaDB [mysql]> select host, user from user;
+-----------+------+
| host      | user |
+-----------+------+
| 127.0.0.1 | root |
| ::1       | root |
| mini      | root |
+-----------+------+
3 rows in set (0.00 sec)

4.2 将与主机名相等的字段改为"%", 我的主机名为mini

MariaDB [mysql]> update user set host='%' where host='mini';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

MariaDB [mysql]> select host, user from user;
+-----------+------+
| host      | user |
+-----------+------+
| %         | root |
| 127.0.0.1 | root |
| localhost | root |
+-----------+------+
3 rows in set (0.00 sec)

4.3 刷新权限表,或重启mariadb服务,一下二选一即可

MariaDB [mysql]> flush privileges;
Query OK, 0 rows affected (0.00 sec)
# or
[root@mini ~]# systemctl restart mariadb

注意:刷新权限表是在数据库中,重启服务是在外部命令行中

4.5 重新远程链接mariadb

centos mariadb,MariaDB,centos,mariadb,linux文章来源地址https://www.toymoban.com/news/detail-847436.html

五、从 CentOS 7 中删除 MariaDB

# 1. 停止 MariaDB 服务。
systemctl stop mariadb.service

# 2. 删除 MariaDB:
yum remove -y mariadb-server mariadb-client

# 3. 删除所有数据文件
$ sudo rm -rf /var/lib/mysql  /etc/my.cnf

到了这里,关于CentOS 7 部署 MariaDB 的 2 种方法的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • 【运维工程师学习】Centos中MySQL替换MariaDB

    把搜索出来的全删除 查看路径里那里还有mysql 全删除 再找 再删 MySQL官网tar包下载链接:https://dev.mysql.com/downloads/mysql/ 如果报错 提示: 可以执行以下命令 打开 /etc/profile 在底部添加如下命令 执行 如果不行进到 /etc/my.cnf 里 在 [mysqld] 下添加 改完密码记得回来去掉 第一次登录

    2024年02月16日
    浏览(38)
  • 安卓/鸿蒙手机使用termux安装mariaDB,Centos搭载jdk,Tomcat制作个人移动版服务器

    安卓/鸿蒙手机使用termux安装mariaDB,Centos Centos搭载jdk,Tomcat制作个人移动版服务器。 本来想把数据库也放到Centos上,结果没安装成功,尴尬… 只好把数据库放到termux上(亲测可用,就是性能较差) termux自带jdk,应该可以把Tomcat放在termux上,有空再试试。 以下动作纯手机操作

    2024年02月03日
    浏览(46)
  • docker部署的mariadb忘记密码

    docker 里的 mariadb 数据库密码忘了,如果以前我会选择直接干掉重装,但是数据怎么办? 1 数据量小 就跳过密码登录进去备份出来 2 想办法改掉密码 我直接选择后者,跳过密码,mariadb10.4以后不能直接改密码了, 尝试了修改 my.cnf 跳过密码 和修改 docker.cnf 跳过密码skip-grant-t

    2024年02月06日
    浏览(75)
  • Ansible部署MariaDB galera集群(多主)

    MariaDB Galera集群是一套基于同步复制的、多主的MySQL集群解决方案,使用节点没有单点故障,可用性高,读写性能高,可扩展性好。 主要特点 : 同步复制,主备无延迟 多主架构允许多个节点成为集群中的主节点,并且所有主节点都可以处理写入请求,这意味着你可以在任何

    2024年02月14日
    浏览(33)
  • Linux下安装/使用mariadb

    rhel7及以上系统默认安装了mariadb(低版本) 如果系统中没有装,虚拟机的话 ,挂载iso,配置iso源, yum -y install mariadb mariadb-server 即可(7/8适用) 注意:只安装mariadb,maraidb服务起不来!!! 下图列举了rhel7.3自带的版本,本章操作以rhel7.3为例 所以,此处记录一下使用系统自带

    2024年02月06日
    浏览(35)
  • Linux中mariadb的安装及使用

    ​ MySQL 和 MariaDB 都是开源数据库技术。MySQL 是最广泛采用的开源数据库。它是许多应用程序和商业产品的主要关系数据库。MariaDB 是 MySQL 的修改版本。在 MySQL 被 Oracle 公司收购后,出于许可和分发方面的问题,MySQL 的原始开发团队制作了 MariaDB。自收购以来,MySQL 和 MariaDB 经

    2024年02月04日
    浏览(32)
  • MariaDB数据库本地部署结合cpolar内网穿透实现远程连接

    本篇教程将使用cpolar内网穿透本地MariaDB数据库,并实现在外公网环境下使用navicat图形化工具远程连接本地内网的MariaDB数据库。 1. 配置MariaDB数据库 1.1 安装MariaDB数据库 进入MariaDB数据库官网https://mariadb.com/downloads/community/,然后下载相应的windows版本 下载好后点击安装,出现设置

    2024年02月03日
    浏览(43)
  • 系统学习Linux-Mariadb高可用MHA

    MHA(MasterHigh Availability)是一套优秀的MySQL高可用环境下故障切换和主从复制的软件。 MHA 的出现就是解决MySQL 单点的问题。 MySQL故障切换过程中,MHA能做到0-30秒内自动完成故障切换操作。 MHA能在故障切换的过程中最大程度上保证数据的一致性,以达到真正意义上的高可用。

    2024年02月12日
    浏览(27)
  • Linux中常用数据库管理系统之MariaDB

    我们生活在信息化时代,经常要跟数据打交道,它在我们的日常生活中无处不在,比如手机支付,微信聊天,淘宝购物,使用的这些在后台都会对应一个叫数据库的存在。数据库就是存储这些数据资料的仓库,那么这些数据是如何被管理的呢?今天我们就来一起了解下数据库

    2024年02月12日
    浏览(31)
  • Windows系统本地部署MariaDB数据库并结合内网穿透实现远程访问

    本篇教程将使用cpolar内网穿透本地MariaDB数据库,并实现在外公网环境下使用navicat图形化工具远程连接本地内网的MariaDB数据库。 1. 配置MariaDB数据库 1.1 安装MariaDB数据库 进入MariaDB数据库官网https://mariadb.com/downloads/community/,然后下载相应的windows版本 下载好后点击安装,出现设置

    2024年01月23日
    浏览(52)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包