MariaDB 安装和配置

一、MariaDB数据库管理系统是MySQL的一个分支,主要由开源社区在维护,采用GPL授权许可。

1、关闭selinux

①修改selinux的配置文件

[root@localhost ~]# vim /etc/selinux/config

SELINUX= disabled

②关闭selinux

[root@localhost ~]# setenforce 0

2、关闭防火墙

[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# systemctl disable firewalld

3、手动安装MariaDB源配置

[root@www yum.repos.d]# cd /etc/yum.repos.d/
[root@www yum.repos.d]# vim /etc/yum.repos.d / mariadb.repo

[mariadb]
name=MariaDB
baseurl=https://mirrors.ustc.edu.cn/mariadb/yum/10.4/centos7-amd64
gpgkey=https://mirrors.ustc.edu.cn/mariadb/yum/RPM-GPG-KEY-MariaDB
gpgchek=1

[root@www yum.repos.d]# yum clean all #清空本地yum缓存

[root@www yum.repos.d]# yum makecache #创建本地yum缓存

4、MariaDB的 安装

[root@www yum.repos.d]# yum -y install MariaDB-server MariaDB-client #安装MDB的服务器和客户端

报错为文件冲突问题

Transaction check error:
file /usr/share/mysql/charsets/Index.xml from install of MariaDB-common-10.4.25-1.el7.centos.x86_64 conflicts with file from package mysql-community-common-5.7.38-1.el7.x86_64 】

解决方法

rpm -qa | grep -i mysql #查看

yum -y remove mysql-community-…… #删除

5、MariaDB的基本配置

①MariaDB 管理命令

[root@localhost yum.repos.d]# systemctl start mariadb #启动
[root@localhost yum.repos.d]# systemctl stop mariadb #关闭
[root@localhost yum.repos.d]# systemctl restart mariadb #重启

②MariaDB 进程查看

[root@localhost yum.repos.d]# ps aux | grep mariadb #查看进程
root 9264 0.0 0.0 112808 968 pts/0 R+ 02:52 0:00 grep –color=auto mariadb
[root@localhost yum.repos.d]# netstat -ntlp | grep 3306 #查看端口3306
[root@localhost yum.repos.d]# lsof -i:3306 #查看端口3306
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
mysqld 9139 mysql 20u IPv6 622570 0t0 TCP *:mysql (LISTEN)

③MariaDB 数据库初始化

为了确保数据库的安全性和正常运转,需要先对数据库程序进行初始化操作。这个初始化操作涉及下面5个步骤。
。设置root管理员在数据库中的密码值(注意,该密码并非root管理员在系统中的密码,这里的密码值默认应该为空,可直接按回车键).

。设置root管理员在数据库中的专有密码。
。随后删除匿名账户,并使用root管理员从远程登录数据库,以确保数据库上运行的业。务的安全性。
。删除默认的测试数据库,取消测试数据库的一系列访问权限。o刷新授权列表,让初始化的设定立即生效。

(1)初始化命令

[root@localhost yum.repos.d]# 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
haven’t set the root password yet, you should just press enter here.

Enter current password for root (enter for none): #初次运行直接回车,设置密码
OK, successfully used password, moving on…

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

You already have your root account protected, so you can safely answer ‘n’.

Switch to unix_socket authentication [Y/n] y
Enabled successfully!

Reloading privilege tables..

… Success!

You already have your root account protected, so you can safely answer ‘n’.

Change the root password? [Y/n] y #是否设置root密码,输入y或者回车,并回答
New password: 6a.Ajn3ihlOaF #设置密码,并确认密码
Re-enter new password: 6a.Ajn3ihlOaF
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 #是否禁止root用户远程登录
… 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 #是否删除test数据库
– 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!

[root@localhost yum.repos.d]#

(2)初始化测试登录

Welcome to the MariaDB monitor. Commands end with ; or \g.

Your MariaDB connection id is 17
Server version: 10.4.25-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)]>

MariaDB [(none)]> show databases; #查看数据库
+——————————–+
| Database |
+——————————–+
| information_schema |
| mysql |
| performance_schema |
+———————————+
3 rows in set (0.003 sec)

MariaDB [(none)]>

④MariaDB 设置utf8字符集

[root@localhost yum.repos.d]# vim /etc/ my.cnf

6、MariaDB 的使用

MariaDB 的使用和MySQL是语句完全是一样的

①基本使用

MariaDB [(none)]> set password =PASSWORD(‘6a.Ajn3ihlOaF’); #修改MySQL密码

Query OK, 0 rows affected (0.003 sec)

MariaDB [(none)]> create database test charset=utf8; #创建一个test数据库,并设置字符集为utf8
Query OK, 1 row affected (0.001 sec)

MariaDB [(none)]> use test; #进入test数据库
Database changed
MariaDB [test]>

MariaDB [test]> create table mytest(id int,name char(32)); #创建mytest数据表
Query OK, 0 rows affected (0.012 sec)

MariaDB [test]> show tables; #查看表

+——————–+
| Tables_in_test |
+——————–+
| mytest |
+——————–+
1 row in set (0.000 sec)

MariaDB [test]> desc mytest; #查看表结构

+——-+————+——–+——-+———+———–+
| Field | Type | Null | Key | Default | Extra |
+——–+————+——-+——-+———+———–+
| id | int(11) | YES | | NULL | |
| name | char(32) | YES | | NULL | |
+———+———–+——–+——-+———+———–+
2 rows in set (0.005 sec)

②简单的增删改查

MariaDB [test]> insert into mytest(id,name) values(1,”zero”),(2,”one”); #向mytest表中插入两条数据
Query OK, 2 rows affected (0.004 sec)
Records: 2 Duplicates: 0 Warnings: 0

MariaDB [test]> select id,name from mytest; #查看id和name列数据
+——–+——+
| id |name|
+——-+——-+
| 1 | zero |
| 2 | one |
+——-+——-+
2 rows in set (0.001 sec)

MariaDB [test]> delete from mytest where id=2; #删除所有id为2的所有数据
Query OK, 1 row affected (0.002 sec)

③关于用户及权限常用命令

MariaDB [test]> create user llg@’localhost’ identified by ‘6a.Ajn3ihlOaF’; #创建用户和密码

Query OK, 0 rows affected (0.004 sec)

MySQL使用grant命令对账号进行授权,grant命令常用格式如下:

grant 权限 on 数据库.表名 to 账号@主机 对特定的数据库中特定的表授权

grant 权限 on 数据库.* to 账号@主机 对特定的数据库中所有表授权

grant 权限1,权限2,权限3 on 数据库.* to 账号@主机 对所有库中的所有表给予多个权限

grant all privileges on . to 账号@主机 对待所有数据库中所有表授予所有权限

drop user 用户名; 删除用户

flush privileges; 刷新权限

④数据库备份与恢复

(1)备份

mysqldump -u root -p –all-databases > /tem/db.dump #备份所有数据库命令

Enter password: 6a.Ajn3ihlOaF

mysqldump -u root -p text > /tmp/test.sql #备份单个数据库命令

Enter password: 6a.Ajn3ihlOaF

(2)恢复

mysql -uroot -p text2< /tmp/test.sql #将备份的数据库导入

Original: https://www.cnblogs.com/blue-wlZ/p/16302774.html
Author: 孤立一点
Title: MariaDB 安装和配置

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/582884/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

  • Java动态脚本Groovy,高级啊!

    前言:请各大网友尊重本人原创知识分享,谨记本人博客: 南国以南i 简介: Groovy是用于Java虚拟机的一种敏捷的动态语言,它是一种成熟的面向对象编程语言,既可以用于面向对象编…

    Linux 2023年6月14日
    0137
  • 重磅!微信官方恢复了个人红包封面的制作入口,限时开放!!.md

    前两天微信开放了个人红包封面,引起了大家欢呼雀跃~ 可惜……没几个小时,因为一个不可描述的原因,官方小程序下架了…… 但是, 现在好…

    Linux 2023年6月15日
    0151
  • 教你搞懂Jenkins安装部署!

    前言:请各大网友尊重本人原创知识分享,谨记本人博客: 南国以南i Jenkins介绍 Jenkins是一个开源软件项目,是基于Java开发的一种持续集成工具,用于监控持续重复的工作…

    Linux 2023年5月27日
    0104
  • 分而治之-快排

    分而治之:把复杂的算法问题按一定的”分解”方法分为等价的规模较小的若干部分,然后逐个解决,分别找出个部分的解,把各部分的解组成整个问题的解。 &#x…

    Linux 2023年6月7日
    091
  • Shell 函数带中横线问题排查

    Shell 中编写的函数,如果函数名中带了中横线,在使用 /bin/sh 执行时会报错。 ➜ subprocess git:(master) ✗ cat kubectl.sh _k…

    Linux 2023年5月28日
    074
  • 安装win10和ubuntu双系统

    2019-06-22 ​ 最近找了一份新的工作,要用到linux,由于之前基本上没有接触过这方面的东西,所以今天捣鼓一下,安装win10和linux双系统,办公研发双不误。如果在安…

    Linux 2023年6月14日
    097
  • ASP.NET Core 2.2 : 二十一. 内容协商与自定义IActionResult和格式化类

    上一章的结尾留下了一个问题:同样是ObjectResult,在执行的时候又是如何被转换成string和JSON两种格式的呢? 本章来解答这个问题,这里涉及到一个名词:”…

    Linux 2023年6月7日
    096
  • samba服务设置与访问共享文件夹

    samba服务设置与访问共享文件夹 linux设置文件夹共享 windows连接共享文件夹(运行->//IP/route) linux连接共享文件夹 1、基本服务安装与配置 …

    Linux 2023年6月14日
    085
  • sql server 增删改(查太多了)

    delete(删除) 使用 delete语句删除表中数据。 delete from 表名 [where where_definition] 如果不使用where子句,将删除表中所有…

    Linux 2023年6月7日
    081
  • 51单片机入门基础介绍

    基本元器件原理及功能 常用元器件 CAP 电容RES 电阻CRYSTAL 晶振7SEG 数码管sounder 蜂鸣器BUTTONLED-BIBY 二极管PN结,P阳极N阴极,电流方…

    Linux 2023年6月7日
    085
  • 【socket】基于Linux使用select上报温度–服务端

    select使用 * – select函数 – select流程图 – 服务端代码实现 select函数 select监视并等待多个文件描述符的…

    Linux 2023年6月13日
    082
  • NoteOfMySQL-12-备份与还原

    一、备份概述 备份不是单纯的复制数据,因为这样无法留下历史记录和系统的DNS或Registry等信息。完整的备份应包括自动化的数据管理与系统的全面恢复,即备份=复制+管理。 1. …

    Linux 2023年6月14日
    066
  • dpdk21.11 添加igb_uio模块

    dpdk 21.11 添加 IGB_UIO模块 IGB_UIO模块 两种添加方式 零、 下载IGB_UIO模块 一、 直接添加到文件中 1.1 复制 dpdk-kmods/linu…

    Linux 2023年6月6日
    092
  • 嵌入式软件架构设计-函数调用

    1 前言 函数调用很好理解,即使刚学没多久的朋友也知道函数调用是怎么实现的,即调用一个已经封装好的函数,实现某个特定的功能。 把一个或者多个功能通过函数的方式封装起来,对外只提供一…

    Linux 2023年6月7日
    084
  • shell升级完整记录

    [root@localhost bash-4.3.30]# cat Makefile |grep prefix prefix = /usr/local exec_prefix = …

    Linux 2023年5月28日
    068
  • 从 Hadoop 到云原生, 大数据平台如何做存算分离

    Hadoop 的诞生改变了企业对数据的存储、处理和分析的过程,加速了大数据的发展,受到广泛的应用,给整个行业带来了变革意义的改变;随着云计算时代的到来, 存算分离的架构受到青睐,企…

    Linux 2023年6月14日
    054
亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球