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)

大家都在看

  • 使用ipmitool配置ipmi(远程控制卡)

    404. 抱歉,您访问的资源不存在。 可能是网址有误,或者对应的内容被删除,或者处于私有状态。 代码改变世界,联系邮箱 contact@cnblogs.com 园子的商业化努力-困…

    Linux 2023年6月7日
    0101
  • docker-部署jumpserver

    Docker 部署 jumpserver 堡垒机 容器部署 jumpserver-1.4.10 服务端 #最好单一个节点 容器运行Mysql 5.6.46 #myql , redi…

    Linux 2023年6月14日
    0104
  • 模拟一个简单的tomcat

    404. 抱歉,您访问的资源不存在。 可能是网址有误,或者对应的内容被删除,或者处于私有状态。 代码改变世界,联系邮箱 contact@cnblogs.com 园子的商业化努力-困…

    Linux 2023年6月11日
    0124
  • 从前端走向后端

    每次过年回老家聚会,遇到不熟悉的亲戚朋友,经常被问到职业是什么。一开始,我总是很认真的回答这个问题,结果常常引出一番尴尬的问答。 &#x201C;&#x4F60;&…

    Linux 2023年6月6日
    0103
  • HTS备份脚本

    #!/bin/bash #program:用于升级前后备份;看时间戳 #author:sundz #version:v1 20220610 创建脚本 备份mysql以及aboss程…

    Linux 2023年6月7日
    074
  • 系列文章分类汇总

    尤娜系列 从前,有一个简单的通道系统叫尤娜…… 尤娜系统的第一次飞行中换引擎的架构垂直拆分改造 四种常用的微服务架构拆分方式 尤娜,我去面试了 专业课回顾 …

    Linux 2023年6月14日
    0107
  • DirectX 使用 Vortice 从零开始控制台创建 Direct2D1 窗口修改颜色

    本文将告诉大家如何使用 Vortice 底层库从零开始,从一个控制台项目,开始搭建一个最简单的使用 Direct2D1 的 DirectX 应用。本文属于入门级博客,期望本文能让大…

    Linux 2023年6月6日
    095
  • 实现邮箱发送验证码功能

    实现注册和忘记密码界面的邮箱发送验证码功能 邮箱验证步骤 本文使用了redis数据库做验证码的缓存,不想用redis数据库也可以直接将验证码放入mysql中,设置验证码有效期即可。…

    Linux 2023年6月7日
    0141
  • Windows Server 新增磁盘处于脱机状态解决办法

    解决方案: Cmd命令行操作如下: 1,进入diskpart模式 2、列出磁盘情况 3、选择脱机的磁盘 4、联机磁盘 5、清除磁盘属性 6、进入磁盘管理,提示初始化 每天记录一点,…

    Linux 2023年6月8日
    0113
  • 非常实用的 Shell 脚本

    检测两台服务器指定目录下的文件一致性 #!/bin/bash<br>#####################################<br>#&a…

    Linux 2023年5月28日
    079
  • ES6

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> &lt…

    Linux 2023年6月13日
    096
  • ThinkPHP 使用 think-queue 实现 redis 消息队列

    简单介绍:消息队列中间件是大型系统中的重要组件,已经逐渐成为企业系统内部通信的核心手段。它具有松耦合、异步消息、流量削峰、可靠投递、广播、流量控制、最终一致性等一系列功能,已经成为…

    Linux 2023年5月28日
    0105
  • 【Java8新特性】- 接口中默认方法修饰为普通方法

    Java8新特性 – 接口中默认方法修饰为普通方法 😄生命不息,写作不止🔥 继续踏上学习之路,学之分享笔记👊 总有一天我也能像各位大佬一样🏆 一个有梦有戏的人 @怒放吧…

    Linux 2023年6月6日
    0112
  • Markdown基本使用

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

    Linux 2023年6月13日
    092
  • 【设计模式】Java设计模式-桥接模式

    【设计模式】Java设计模式 – 桥接模式 😄 不断学习才是王道🔥 继续踏上学习之路,学之分享笔记👊 总有一天我也能像各位大佬一样🏆原创作品,更多关注我CSDN: 一个…

    Linux 2023年6月6日
    0130
  • 3. 文件与I/O

    文件与I/OO read&#x7CFB;&#x7EDF;&#x8C03;&#x7528; 函数原型 一旦有了与一个打开文件描述相连的文件描述符,只要…

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