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.bakroot@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 multiversedeb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiversedeb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiversedeb http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiversedeb 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-installationNOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDBSERVERS 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 distributionCopyright (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 distributionCopyright (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)

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

如若内容造成侵权/违法违规/事实不符,请联系长河编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

022、Python+fastapi,第一个Python项目走向第22步:ubuntu 24.04 docker 安装mysql8集群、redis集群(三)

这次来安装mysql8了,以前安装不是docker安装,这个我也是第一次,人人都有第一次嚒 前言 前面的redis安装还是花了点时间的,主要是网上教程,各有各的好,大家千万别取其长处,个人觉得这个环境影响…

【C语言】分支和循环(上)

【C语言】分支和循环(上) 1、if语句1.2 else1.3分支中包含多条语句1.4嵌套if1.5悬空else问题 2、关系操作符3、条件操作符4、逻辑操作符:与、或、非(取反)(&&,||,&#xff0…

深入理解网络原理3----TCP核心特性介绍(上)【面试高频考点】

文章目录 前言TCP协议段格式一、确认应答【保证可靠性传输的机制】二、超时重传【保证可靠性传输的机制】三、连接管理机制【保证可靠性传输的机制】3.1建立连接(TCP三次握手)---经典面试题3.2断开连接(四次挥手)3.3TCP状态转换 四…

「 网络安全常用术语解读 」通用漏洞报告框架CVRF详解

1. 背景 ICASI在推进多供应商协调漏洞披露方面处于领先地位,引入了通用漏洞报告框架(Common Vulnerability Reporting Format,CVRF)标准,制定了统一安全事件响应计划(USIRP)的原则,…

JSP与JavaBean

目录 一、JavaBean是什么 二、创建JavaBean 三、在JSP中使用JavaBean 1、按照Java语法直接使用 2、<jsp:useBean>动作 Bean的加载原理 scope属性的不同取值 3、<jsp:setProperty>动作 设置为一个表达式的值或字符序列 通过表单的参数的值来设置Bean的相应…

Find My无人机|苹果Find My技术与无人机结合,智能防丢,全球定位

无人机是利用无线电遥控设备和自备的程序控制装置操纵的不载人飞机&#xff0c;或者由车载计算机完全地或间歇地自主地操作。无人机按应用领域&#xff0c;可分为军用与民用。军用方面&#xff0c;无人机分为侦察机和靶机。民用方面&#xff0c;无人机行业应用&#xff0c;是无…

43 单例模式

目录 1.什么是单例模式 2.什么是设计模式 3.特点 4.饿汉和懒汉 5.峨汉实现单例 6.懒汉实现单例 7.懒汉实现单例&#xff08;线程安全&#xff09; 8.STL容器是否线程安全 9.智能指针是否线程安全 10.其他常见的锁 11.读者写者问题 1. 什么是单例模式 单例模式是一种经典的&a…

多多搜索推广计划怎么设置

拼多多推广可以使用3an推客。3an推客&#xff08;CPS模式&#xff09;给商家提供的营销工具&#xff0c;由商家自主设置佣金比例&#xff0c;激励推广者去帮助商家推广商品链接&#xff0c;按最终有效交易金额支付佣金&#xff0c;不成交不扣费。是商家破零、积累基础销量的重要…

自动化机器学习——网格搜索法:寻找最佳超参数组合

自动化机器学习——网格搜索法&#xff1a;寻找最佳超参数组合 在机器学习中&#xff0c;选择合适的超参数是模型调优的关键步骤之一。然而&#xff0c;由于超参数的组合空间通常非常庞大&#xff0c;手动调整超参数往往是一项耗时且困难的任务。为了解决这个问题&#xff0c;…

连接HiveMQ代理器实现MQTT协议传输

先下载MQTTX: MQTTX: Your All-in-one MQTT Client Toolbox 使用线上免费的MQTTX BROKER:The Free Global Public MQTT Broker | Try Now | EMQ 打开MQTTX&#xff0c;创建连接&#xff0c;点击NEW SUBSCRIPTION,创建一个主题&#xff0c;这里使用test/topic,在下面Json中填写…

使用 ORPO 微调 Llama 3

原文地址&#xff1a;https://towardsdatascience.com/fine-tune-llama-3-with-orpo-56cfab2f9ada 更便宜、更快的统一微调技术 2024 年 4 月 19 日 ORPO 是一种新的令人兴奋的微调技术&#xff0c;它将传统的监督微调和偏好校准阶段合并为一个过程。这减少了训练所需的计算…

Java零基础入门到精通_Day 8

1.API 应用程序接口 Java API:指的就是JDK 中提供的各种功能的Java类这些类将底层的实现封装了起来&#xff0c;我们不需要关心这些类是如何实现的&#xff0c;只需要学习这些类如何使用即可&#xff0c;我们可以通过帮助文档来学习这些API如何使用。 2. String String 类…

【副本向】Lua副本逻辑

副本生命周期 OnCopySceneTick() 子线程每次心跳调用 --副本心跳 function x3323_OnCopySceneTick(elapse)if x3323_g_IsPlayerEnter 0 thenreturn; -- 如果没人进入&#xff0c;则函数直接返回endif x3323_g_GameOver 1 thenif x3323_g_EndTick > 0 thenx3323_CountDown…

循环神经网络完整实现(Pytorch 13)

一 循环神经网络的从零开始实现 从头开始基于循环神经网络实现字符级语言模型。 %matplotlib inline import math import torch from torch import nn from torch.nn import functional as F from d2l import torch as d2lbatch_size, num_steps 32, 35 train_iter, vocab …

分布式websocket IM即时通讯聊天开源项目如何启动

前言 自己之前分享了分布式websocket的视频有同学去fork项目了&#xff0c;自己启动一下更方便理解项目嘛。然后把项目启动需要的东西全部梳理出来。支持群聊单聊,表情包以及发送图片。 支持消息可靠&#xff0c;消息防重&#xff0c;消息有序。同时基础架构有分布式权限&…

OneFlow深度学习框原理、用法、案例和注意事项

本文将基于OneFlow深度学习框架&#xff0c;详细介绍其原理、用法、案例和注意事项。OneFlow是由中科院计算所自动化研究所推出的深度学习框架&#xff0c;专注于高效、易用和扩展性强。它提供了一种类似于深度学习库的接口&#xff0c;可以用于构建神经网络模型&#xff0c;并…

Android4.4真机移植过程笔记(三)

如果文章字体看得不是很清楚&#xff0c;大家可以下载pdf文档查看&#xff0c;文档已上传&#xff5e;oo&#xff5e; 7、安装加密APK 需要修改文件如下&#xff1a; 相对Android4.2改动还是蛮大的&#xff0c;有些文件连路径都变了: //Android4.2 1、frameworks/native/libs…

STL速查

容器 (Containers) 图解容器 支持随机访问 stringarrayvectordeque支持支持支持支持 string 类 构造函数 string(); ------创建一个空的字符串 例如: string str;string(const char* s); ------使用字符串s初始化string(const string& str); ------拷贝构造 赋值操作…

C++学习--点滴记录011

11函数提高 11.1 函数默认参数 在C中&#xff0c;函数的形参列表中的形参可以有默认值 语法&#xff1a; 返回值类型 函数名 &#xff08;参数 默认值&#xff09;{} 示例&#xff1a; #include <iostream> using namespace std;int func(int a, int b 10, int c …

网络基础-网络设备介绍

本系列文章主要介绍思科、华为、华三三大厂商的网络设备 网络设备 网络设备是指用于构建和管理计算机网络的各种硬件设备和设备组件。以下是常见的网络设备类型&#xff1a; 路由器&#xff08;Router&#xff09;&#xff1a;用于连接不同网络并在它们之间转发数据包的设备…