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)

大家都在看

  • Linux系统僵尸进程详解

    大安好,我是良许。 在本文中,我们将讨论什么是僵尸进程,如何创建僵尸进程,以及如何终止僵尸进程。 [En] In this article, we will discuss wha…

    Linux 2023年5月27日
    0106
  • 如何正确地使用Entity Framework Database First

    毕设依旧在不紧不慢地以每天解决一个问题的进度进行中。今天遇到的问题就是在建立数据模型时遇到的。因为项目是基于数据库构建的,所以理所应当地采用DB First来构造实体类和DbCon…

    Linux 2023年6月14日
    0118
  • 《拉钩课程 — 重学数据结构与算法》学习笔记

    一、代码效率优化方法论 1、数据结构,从名字上来看是数据的结构,也就是数据的组织方式。 2、复杂度是衡量代码运行效率的重要度量因素。 3、复杂度是一个关于输入数据量 n 的函数。假…

    Linux 2023年6月16日
    0111
  • linux命令之tar 解压 压缩

    tar(全称:tape archive )命令用于备份文件。tar 是用来 创建或者 还原备份文件的工具程序,它可以加入,解开备份文件内的文件。tar linux说明 tar [&…

    Linux 2023年5月27日
    083
  • Java中QueryWrapper的基本使用

    1.单表查询 对应的sql语句为: select * from student where name = ‘?’ and class like ‘%?%’ and age betw…

    Linux 2023年6月7日
    0108
  • Linux下IPC之共享内存的使用方法

    基本参考 《Unix环境高级编程》 第14.9节共享内存来学习。 需要说明的 讲shmget(key,size, flag)函数时,书上大概意识是说, 想访问已有的shm时,key…

    Linux 2023年6月7日
    084
  • 三种移除list中的元素(可靠)

    /** * 直接使用foreach方法移除list中的元素会抛异常 * Exception in thread "main" java.util.Concurr…

    Linux 2023年6月7日
    095
  • 积分排名查看

    1年05个月 2018-9-17 1年04个月 2018-9-04 1年04个月 2018-8-23 1年04个月 2018-8-21 posted @2018-08-21 21:…

    Linux 2023年6月7日
    098
  • 项目相关环境docker版安装教程总结

    项目环境docker及docker-compose文档 1、Linux环境介绍 centos7.6 16G以上内存空间(至少8G) 2、静态IP设置 1、找到配置文件 cd /et…

    Linux 2023年6月7日
    086
  • 【抄】Shell正则表达式

    shell 正则语法基础 copy from: https://man.linuxde.net/docs/shell_regex.html 正则表达式的分类 基本的正则表达式(Ba…

    Linux 2023年5月28日
    0115
  • 魔域来了H5游戏详细图文架设教程

    前言 想体验热血传奇的战场吗?想体验满级VIP的尊贵吗?想体验榜一大佬的无敌寂寞吗?各种极品炫酷时装、坐骑、翅膀、宠物通通给你,就在魔域来了H5! 本文讲解魔域来了架设教程,想研究…

    Linux 2023年6月7日
    0122
  • OpenStack glance对接swift

    配置 切换环境变量 [root@controller ~]# source keystonerc_admin 复制glance配置文件备份 [root@controller ~(k…

    Linux 2023年6月8日
    093
  • [ Skill ] 如何获取库中的 top cell

    https://www.cnblogs.com/yeungchie/ top cell 的一个特点就是没有被其他的单元所调用,下面举例获取某个库中的 top cell。 1. 获取…

    Linux 2023年6月7日
    0103
  • Redis 集群

    三高架构:并发,性能,可用 主从复制 主从复制:将 master 中的数据即时、有效的复制到 slave 中 特征:一个 master 可以拥有多个 slave,一个 slave …

    Linux 2023年5月28日
    0111
  • Markdown基本使用

    元素 Markdown 语法 [标题(Heading)] [粗体(Bold)] [斜体(Italic)] [引用块(Blockquote)] [有序列表(Ordered List)…

    Linux 2023年6月13日
    092
  • ETCD分布式存储部署

    一、ETCD 概述 ETCD 是一个分布式一致性k-v存储系统,可用于服务注册发现与共享配置。具有一下优点: 简单: 相比于晦涩难懂的paxos算法,etcd基于相对简单且易实现的…

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