Ubuntu编译安装MariaDB并进行初始化配置

Ubuntu编译安装MariaDB并进行初始化配置

  • 1. 编译安装MariaDB
  • 2. 配置MariaDB
  • 3. Docker安装MariaDB

1. 编译安装MariaDB

   MariaDB官方安装文档:https://mariadb.com/kb/en/Build_Environment_Setup_for_Linux/
   下载MariaDB源码:https://mariadb.org/mariadb/all-releases/
在这里插入图片描述
在这里插入图片描述

   查看操作系统的版本:

root@mysql-demo:~# lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 20.04.1 LTS
Release:	20.04
Codename:	focal

   更新apt源:

root@mysql-demo:~# mv /etc/apt/sources.list /etc/apt/sources.list.bak

root@mysql-demo:~# cat /etc/apt/sources.list
deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
 
deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
 
deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
 
deb http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
 
deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse

   根据MariaDB官方项目文档,我们需要安装依赖:

root@newtv:~# apt-get update
root@newtv:~# apt-get install cmake build-essential openssl libssl-dev bison libncurses-dev

   解压并进入源码内:

root@newtv:~# tar xf mariadb-11.3.2.tar.gz
cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \       # MariaDB的安装地址
-DMYSQL_DATADIR=/mydata/data \                          # 数据库文件存放地址
-DWITH_INNOBASE_STORAGE_ENGINE=1 \                      # 支持数据库innobase引擎
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \                       # 支持数据库archive引擎
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \                     # 支持数据库blackhole存储引擎
-DWITH_READLINE=1 \
-DWITH_SSL=system \
-DWITH_ZLIB=system \
-DWITH_LIBWRAP=0 \
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock \                     # sock文件编译后存放地址
-DDEFAULT_CHARSET=utf8 \                                # 字符集utf8
-DDEFAULT_COLLATION=utf8_general_ci \                   # 校验字符
-DENABLED_LOCAL_INFILE=1                                # 允许本地导入数据


root@newtv:~/mariadb-11.3.2# make                       # 这个过程很长,或者使用下面的方式
root@newtv:~/mariadb-11.3.2# make -j 4                  # 如果你的Linux设备是多核,可以加上-j参数以加快编译速度
root@newtv:~/mariadb-11.3.2# make install 

2. 配置MariaDB

   创建mysql用户组和用户:

root@mysql-demo:~# groupadd -r mysql
root@mysql-demo:~#  useradd -g mysql -r -s /sbin/nologin mysql

   创建SQL目录(上文编译参数内):

root@mysql-demo:~# mkdir /mydata/data -p
root@mysql-demo:~# chown mysql:mysql /mydata/data

   进入MariaDB安装地址,修改文件归属到mysql用户:

root@mysql-demo:~# cd /usr/local/mysql
# chgrp mysql ./*

   初始化脚本:
   使用MariaDB自带的脚本,对MariaDB进行初始化(当前在MariaDB安装目录内,即:/usr/local/mysql内):

root@mysql-demo:~#  /usr/local/mysql/scripts/mysql_install_db --user=mysql --datadir=/mydata/data

   初始化完成后,需要设置my.cnf文件,早期版本的MySQL和MariaDB都有提供my.cnf为模版,现在已经没有提供,需要手动创建,手动创建到/etc下。

root@mysql-demo:~# cat /etc/my.cnf 
# Begin /etc/mysql/my.cnf
# The following options will be passed to all MySQL clients
[client]
port            = 3306
socket          = /tmp/mysql.sock

# The MySQL serve
[mysqld]
port            = 3306
socket          = /tmp/mysql.sock
# MariaDB安装地址
basedir         = /usr/local/mysql
datadir         = /mydata/data
#skip-external-locking
key_buffer_size = 16M
max_allowed_packet = 1M
sort_buffer_size = 512K
net_buffer_length = 16K
myisam_sort_buffer_size = 8M
skip-name-resolve = 0

# MariaDB不监听任何IPTCP端口
# skip-networking

# required unique id between 1 and 2^32 - 1
server-id       = 1
innodb_data_file_path = ibdata1:12M:autoextend

# You can innodb_buffer_pool_size up to 50 - 80 %
# of RAM but beware of setting memory usage too high
innodb_buffer_pool_size = 32M
innodb_log_file_size = 48M
innodb_log_buffer_size = 16M
innodb_flush_log_at_trx_commit = 1
innodb_lock_wait_timeout = 50
innodb_write_io_threads = 4
innodb_read_io_threads = 4
innodb_force_recovery =1

[mysqldump]
quick
max_allowed_packet = 16M

[mysql]
no-auto-rehash
# Remove the next comment character if you are not familiar with SQL
#safe-updates

[isamchk]
key_buffer = 20M
sort_buffer_size = 20M
read_buffer = 2M
write_buffer = 2M

[myisamchk]
key_buffer_size = 20M
sort_buffer_size = 20M
read_buffer = 2M
write_buffer = 2M

[mysqlhotcopy]
interactive-timeout
# End /etc/my.cnf

   创建一个MariaDB服务器系统服务文件:

root@mysql-demo:~# cat /usr/lib/systemd/system/mysql.service
[Unit]
Description=MariaDB

[Service]
LimitNOFILE=10000
Type=simple
User=mysql
Group=mysql
PIDFile=/mydata/data/microServer.pid
ExecStart=/usr/local/mysql/bin/mysqld_safe --datadir=/mydata/data
ExecStop=/bin/kill -9 $MAINPID

[Install]
WantedBy=multi-user.target

   设置好后,使用systemctl进行启动即可:

root@mysql-demo:~# systemctl daemon-reload
root@mysql-demo:~# systemctl start mysql.service
root@mysql-demo:~# systemctl status mysql.service

   还要添加MariaDB安装目录下的bin目录到环境变量内,如:

root@mysql-demo:~# vim /etc/profile
export PATH=/usr/local/mysql/bin:$PATH
root@mysql-demo:~# cd /usr/local/mysql/bin
root@mysql-demo:/usr/local/mysql/bin# ./mariadb-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] n
 ... skipping.

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

Change the 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] n
 ... skipping.

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!

   完成上述步骤后,其实MariaDB就可以使用了,但是我们需要设置账号,用来远程访问。

root@mysql-demo:/usr/local/mysql/bin# mysql -u root -p
mysql: Deprecated program name. It will be removed in a future release, use '/usr/local/mysql/bin/mariadb' instead
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 9
Server version: 11.3.2-MariaDB Source distribution

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)]> select user,host from mysql.user;
+-------------+-----------+
| User        | Host      |
+-------------+-----------+
| PUBLIC      |           |
| mariadb.sys | localhost |
| mysql       | localhost |
| root        | localhost |
+-------------+-----------+
4 rows in set (0.002 sec)

MariaDB [(none)]> use mysql
MariaDB [mysql]> grant all privileges on *.* to 'root'@'%' identified by 'Newtv123.com' with grant option;
MariaDB [mysql]> flush privileges;
MariaDB [mysql]> select user,host from mysql.user;
+-------------+-----------+
| User        | Host      |
+-------------+-----------+
| PUBLIC      |           |
| root        | %         |
| mariadb.sys | localhost |
| mysql       | localhost |
| root        | localhost |
+-------------+-----------+
5 rows in set (0.002 sec)

   在生产环境下访问MySQL时, 是需要申请访问权限的, 就算你知道MySQL的用户名和密码, 但是你没有权限访问MySQL的那台机器, 所以这样也是安全的, 只要运维人员把权限控制到位就可以了。

MariaDB [mysql]> CREATE USER 'mysql_test'@'%' IDENTIFIED BY 'ZorFEtc';
MariaDB [mysql]> GRANT ALL PRIVILEGES ON *.* TO 'mysql_test'@'172.26.10.%';
MariaDB [mysql]> GRANT ALL PRIVILEGES ON *.* TO 'mysql_test'@'192.168.%.%';
MariaDB [mysql]> GRANT ALL PRIVILEGES ON *.* TO 'mysql_test'@'localhost';


MariaDB [mysql]> CREATE USER 'mysql_cdh'@'%' IDENTIFIED BY 'ZoDH';
MariaDB [mysql]> GRANT ALL PRIVILEGES ON *.* TO 'mysql_cdh'@'172.26.30.%';
MariaDB [mysql]> GRANT ALL PRIVILEGES ON *.* TO 'mysql_cdh'@'192.168.%.%';
MariaDB [mysql]> GRANT ALL PRIVILEGES ON *.* TO 'mysql_cdh'@'localhost';

MariaDB [mysql]> FLUSH PRIVILEGES;
删除用户:
MariaDB [(none)]> DROP USER 'mysql_test'@'172.26.3.%';

3. Docker安装MariaDB

root@newtv:~#  docker pull mariadb
root@newtv:~#  docker run --name some-mariadb \
-p 3306:3306 \
-e MYSQL_ROOT_PASSWORD=babyshen@2024  \
-e MYSQL_DATABASE=mydb \
-e MYSQL_USER=myuser \
-e MYSQL_PASSWORD=mypassword  \
-v /var/lib/mysql:/var/lib/mysql  \
-d mariadb
root@newtv:~# ss -tnlp | grep 3306
LISTEN 0      4096         0.0.0.0:3306      0.0.0.0:*    users:(("docker-proxy",pid=166277,fd=4))   
LISTEN 0      4096            [::]:3306         [::]:*    users:(("docker-proxy",pid=166284,fd=4))  

   使用其他客户端测试连接MySQL容器:

root@mysql-demo:~# mysql -u root -p -h172.26.160.105
mysql: Deprecated program name. It will be removed in a future release, use '/usr/local/mysql/bin/mariadb' instead
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 3
Server version: 11.3.2-MariaDB-1:11.3.2+maria~ubu2204 mariadb.org binary distribution

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)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mydb               |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
5 rows in set (0.002 sec)


MariaDB [(none)]> select user from mysql.user;
+-------------+
| User        |
+-------------+
| myuser      |
| root        |
| healthcheck |
| healthcheck |
| healthcheck |
| mariadb.sys |
| root        |
+-------------+
7 rows in set (0.004 sec)

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:/a/581060.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

Spring Boot 如何实现缓存预热

Spring Boot 实现缓存预热 1、使用启动监听事件实现缓存预热。2、使用 PostConstruct 注解实现缓存预热。3、使用 CommandLineRunner 或 ApplicationRunner 实现缓存预热。4、通过实现 InitializingBean 接口,并重写 afterPropertiesSet 方法实现缓存预热。 1、使用…

TCP-模拟BS架构通信

简介 bs是通过浏览器进行访问的每次访问都会开启一个短期的socket用来访问服务器的资源 响应报文的格式 服务端 bs架构中的b是浏览器,不需要我们书写,我们只需要书写服务端即可 服务端 public class Server {public static void main(String[] args) {S…

[C++]22:C++11_part_one

C11 一.列表初始化:1.{}初始化:2.C11扩大了列表初始化的范围:3.std::initializer_list1.简单类型的列表初始化:2.复杂类型的列表初始化3.实现vector的列表初始化4.实现list的列表初始化:5.不支持列表初始化&#xff1a…

制作一个RISC-V的操作系统十六-系统调用

文章目录 用户态和内核态mstatus设置模式切换核心流程封装代码背景解释代码示例解析解释目的 用户态和内核态 mstatus设置 此时UIE设置为1和MPIE为1,MPP设置为0 代表当前权限允许UIE中断发生,并且在第一个mret后将权限恢复为用户态,同时MIE也…

易错知识点(学习过程中不断记录)

快捷键专区: 注释:ctrl/ ctrlshift/ 保存:ctrls 调试: 知识点专区: 1基本数据类型 基本数据类型有四类:整型、浮点型、字符型、布尔型(Boolean), 分为八种&#xff…

UE5 GAS开发P40 周期性效果,持续治疗

Periodic Gameplay Effects周期性的游戏效果 它们在一段时间内以固定的间隔重复应用到目标上。这种效果通常用于表示持续性伤害、治疗或其他影响,例如中毒、灼烧或回复效果。 修改GE_CrystalHeal,在Period改为每0.1秒执行一次 假如同时有三个持续时间在进行,那么这…

STM32与OLED显示屏通信(四针脚和七阵脚)

系列文章目录 STM32单片机系列专栏 C语言术语和结构总结专栏 文章目录 1. 单片机调试 2. OLED简介 3. 接线 4. OLED驱动函数 4.1 四针脚版本 OLED.c OLED.h OLED_Font.h 4.2 七针脚版本 引脚连接 OLED.c OLED.h OLED_Font.h 5. 主函数 工程文件模板 1. 单片机…

linux下安装deepspeed

安装步骤 一开始安装deepspeed不可以使用pip直接进行安装。 这时我们需要利用git进行clone下载到本地: git clone https://github.com/microsoft/DeepSpeed.git 进入到deepspeed的安装目录下 cd /home/bingxing2/ailab/group/ai4agr/wzf/Tools/DeepSpeed 激活…

verilog 从入门到看得懂---matlab 自动生成verilog

matlab 的强大不用多说,以前经常用simulink 生成c,最近尝试用simulink进行了verilog的生成,方法也很简单。 一个简单的示例如下。 1,新建一个模型文件,并且根据需要进行模型搭建 2.配置HDL生成模块 3.点击 generation…

纯血鸿蒙APP实战开发——全局状态保留能力弹窗

全局状态保留能力弹窗 介绍 全局状态保留能力弹窗一种很常见的能力,能够保持状态,且支持全局控制显隐状态以及自定义布局。使用效果参考评论组件 效果图预览 使用说明 使用案例参考短视频案例 首先程序入口页对全局弹窗初始化,使用Globa…

Linux学习之路 -- 进程篇 -- 自定义shell的编写

前面介绍了进程程序替换的相关知识&#xff0c;接下来&#xff0c;我将介绍如何基于前面的知识&#xff0c;编写一个简单的shell&#xff0c;另外本文的所展示的shell可能仅供参考。 目录 <1>获取用户的输入和打印命令行提示符 <2>切割字符串 <3>执行这个…

qt-C++笔记之滑动条QSlider和QProgressBar进度条

qt-C笔记之滑动条QSlider和QProgressBar进度条 —— 2024-04-28 杭州 本例来自《Qt6 C开发指南》 文章目录 qt-C笔记之滑动条QSlider和QProgressBar进度条1.运行2.阅读笔记3.文件结构4.samp4_06.pro5.main.cpp6.widget.h7.widget.cpp8.widget.ui 1.运行 2.阅读笔记 3.文件结构…

智慧供热一站式热网平衡多功能集成系统

供热管理地域分散的现实&#xff0c;决定必须采用先进技术手段开发软件系统&#xff0c;使各管理单位互联互通。在多年技术积累的基础上&#xff0c;公司采用目前成熟而且领先的技术架构&#xff0c;研发了适用于多个组织机构集中式管理的供热管理软件。使管理在技术上不再受地…

经典的目标检测算法有哪些?

一、经典的目标检测算法有哪些&#xff1f; 目标检测算法根据其处理流程可以分为两大类&#xff1a;One-Stage&#xff08;单阶段&#xff09;算法和Two-Stage&#xff08;两阶段&#xff09;算法。以下是一些经典的目标检测算法&#xff1a; 单阶段算法: YOLO (You Only Loo…

Java集合框架-Collection-queue

目录 一、Deque二、ArrayDequeArrayDeque层次结构图ArrayDeque概述ArrayDeque底层数据结构ArrayDeque常用方法(简略) 三、PriorityQueuePriorityQueue层次结构图PriorityQueue概述PriorityQueue 底层数据结构PriorityQueue常用方法(详细) Java里有一个叫做Stack的类&#xff0c…

[tkinter实现]汉字笔顺小软件

软件简介 本软件旨在帮助小学生通过互动式学习掌握汉字的基本笔画和笔顺。软件采用Tkinter库构建&#xff0c;提供了一个用户友好的图形界面&#xff0c;适合小学生使用。 主要功能&#xff1a; 汉字展示&#xff1a;软件能够展示单个汉字&#xff0c;并以动画形式演示其标准…

SAP SALV研究

1.SALV SALV用的是类cl_salv_table下的相关方法,一般用于对话框或者功能要求比较简单的数据显示,比如明细数据显示,不能单元格编辑或者某行某列编辑,可以实现全部数据编辑(实用性不强),如要实现编辑可参考这篇博文 https://mp.weixin.qq.com/s?__biz=MzU1MDAzMDY3MQ==…

车载系统的 加减串器应用示意

overview 车载系统上使用加减串器来实现camera&#xff0c; led液晶显示屏等 图像数据的远距离传输&#xff0c;将原先在短距离传输视频信号的mipi csi&#xff0c;dsi 等的TX&#xff0c;RX中间&#xff0c;插入加减串器&#xff0c;实现长距离的可靠传输。 示意图如下 往往…

开发 Chrome 浏览器插件入门

前言 简介 Chrome 插件是扩展 Chrome 浏览器的功能的软件程序。它们可以执行各种任务&#xff0c;例如阻止广告、增强隐私、添加新功能等等。 要开始编写 Chrome 插件&#xff0c;你需要掌握以下&#xff1a; 1.JavaScript语言 2.html 3.css 4.会使用chrome扩展开发手册…

C#设计树形程序界面的方法:创建特殊窗体

目录 1.TreeView控件 2.实例 &#xff08;1&#xff09;Resources.Designer.cs &#xff08;2&#xff09;Form1.Designer.cs &#xff08;3&#xff09;Form1.cs &#xff08;4&#xff09;生成效果 以树形来显示程序的菜单&#xff0c;可以更直观、更快捷地对窗体进行…