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.mzph.cn/diannao/4581.shtml

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

相关文章

Springboot + MySQL + html 实现文件的上传、存储、下载、删除

实现步骤及效果呈现如下: 1.创建数据库表: 表名:file_test 存储后的数据: 2.创建数据库表对应映射的实体类: import com.baomidou.mybatisplus.annotation.IdType;import com.baomidou.mybatisplus.annotation.Table…

MySQL使用Sequence创建唯一主键

目录 第一章、快速了解Sequence1.1)是什么?为什么使用1.2)Sequence和自增主键的区别 第二章、在MySQL中使用Sequence2.1)创建mysql_sequence表2.1.1)创建表2.1.2)插入数据 2.2)创建函数2.2.1&am…

vue使用debugger调试代码

1.在vue.config.js中 在你的vue文件vue.config.js中找到如下configureWebpack位置,加入devtool:"source map",重新启动项目debugger即可生效。

分享:9.3版本无缝导入AVEVA PDMS高版本工程12.0,12.1,E3D

9.3版本可以无缝导入AVEVA PDMS的工程。 UKP3d导入AVEVA PDMS工程的方法 http://47.94.91.234/forum.php?modviewthread&tid163583&fromuid6 (出处: 优易软件-工厂设计软件专家) (从AVEVA PDMS导出时元件和等级的功能我们正做收尾工作,到时可以…

如何进行制造设备数据汇集,发挥数据的价值?

数字化转型正深刻推动制造企业实现远程监控、提高生产效率、降低生产成本、优化产品质量及明晰精细化方向。并且工业互联网的发展离不开工业数据的应用,而制造设备数据汇集正是应用的基础。但制造设备数据汇集存在以下难点及痛点: 1、安全把控难 关键的…

Mysql基础(一)DDL、DML、DQL、DCL 扫盲之DDL语句

一 扫盲 SQL语句根据其功能主要分为四类:DDL、DML、DQL、DCL说明: 本篇章只会粗略的分类,不会展开细节讲解 1、DDL(Data Definition Language)说明: 是一组用于定义和管理数据库结构的语句2、DML(Data Ma…

RLDP协议原理与应用

RLDP概述 l RLDP全称是Rapid Link Detection Protocol(快速链路检测协议),是锐捷网络自主开发的,用于快速检测以太网链路故障的链路协议。 l 一般的以太网链路检测机制都只是利用物理连接的状态,通过物理层的自动协…

张大哥笔记:我付钱了,我就是大爷?

很抱歉用这个当做标题,来给大家分享一些电商的故事!大家好,我是张大哥,今天聊聊在电商路上遇到过的奇葩买家? 比如最近我在做PDD的时候,就会遇到很多莫名其妙的sha子,咱是知识份子,肯…

远程桌面连接不上个别服务器的问题分析与解决方案

在日常的IT运维工作中,远程桌面连接(RDP,Remote Desktop Protocol)是我们经常使用的工具之一,用于管理和维护远程服务器。然而,有时我们可能会遇到无法连接到个别服务器的情况。针对这一问题,我…

微信小程序4~6章总结

目录 第四章 页面组件总结 4.1 组件的定义及属性 4.2 容器视图组件 4.2.1 view 4.2.2 scroll-view 4.2.3 swiper 4.3 基础内容组件 4.3.1 icon ​编辑 4.3.2 text 4.3.3 progress ​编辑 4.4 表单组件 4.4.1 button 4.4.2 radio 4.4.3 checkbox 4.4.4 switch …

C语言--贪吃蛇小游戏

目录 一、Win32API介绍 1.1Win32API 1.2控制台程序 1.3控制台屏幕上的坐标COORD 1.4GetStdHandle 1.5GetConsoleCursorInfo 1.6 CONSOLE_CURSOR_INFO 1.7 SetConsoleCursorInfo 1.8SetConsoleCursorPosition 1.9GetAsyncKeyState 二、贪吃蛇游戏设计与分析 2.1地图 …

网站内容下载软件有哪些 网站内容下载软件推荐 网站内容下载软件安全吗 idm是啥软件 idm网络下载免费

一招搞定网页内容下载,并且各大网站通用!绕过资源审查,所有网站内容随意下载。解锁速度限制,下载即高速无视网站限速。跳过会员充值,所有VIP资源免费下载。有关网站内容下载软件有哪些,网站内容下载软件推荐…

【leetcode】快慢指针相关题目总结

141. 环形链表 判断链表是否有环:如果链表中存在环,则在链表上不断前进的指针会一直在环里绕圈子,且不能知道链表是否有环。使用快慢指针,当链表中存在环时,两个指针最终会在环中相遇。 /*** Definition for singly-…

Ubuntu-22.04电源选项设置

提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档 文章目录 前言说明一、图形设置二、命令行设置1.查看支持的模式2.设置新模式 总结 前言 我们使用Windows都知道电源选项有省电、平衡和高性能模式。其实Ubuntu-22.04也有这个…

【Linux】文件系统

送给大家一句话: 你的任务,就是珍惜你自己的人生,而且还要比之前任何时候更加珍惜。 – 东野圭吾 文件系统 1 前言2 物理磁盘3 磁盘的存储结构4 抽象理解磁盘储存5 引入文件系统 (如何管理磁盘文件)5.1 了解文件系统5.…

基于 SpringCloud 的在线交易平台乐优商城的设计与实现(六)

目录 第六章 系统测试 6.1 功能性测试 6.1.1 商家后台功能测试 6.1.2 前台功能测试 6.2 非功能性测试 6.3 本章小结 结束语 参考文献 前面内容请移步 基于 SpringCloud 的在线交易平台乐优商城的设计与实现(五) 相关免费源码资源 乐优商城…

深入理解分布式事务① ---->分布式事务基础(四大特性、五大类型、本地事务、MySQL并发事务问题、MySQL事务隔离级别命令设置)详解

目录 深入理解分布式事务① ---->分布式事务基础(四大特性、五大类型、本地事务、MySQL并发事务问题、MySQL事务隔离级别命令设置)详解事务的基本概念1、什么是事务?2、事务的四大特性2-1:原子性(Atomic&#xff09…

黑烟车智能电子抓拍系统大幅度节约人力物力

黑烟车智能电子抓拍系统大幅度节约人力物力,之前黑烟车监测通过执勤交警人工现场监测会耗费大量人力物力,效率较低,现在通过黑烟车智能电子抓拍系统可以大辅导提升监测效率,遗漏少,效率高,值得大力推广。 黑…

【Python数据库】MongoDB

文章目录 [toc]数据插入数据查询数据更新数据删除 个人主页:丷从心 系列专栏:Python数据库 学习指南:Python学习指南 数据插入 from pymongo import MongoClientdef insert_data():mongo_client MongoClient(hostlocalhost, port27017)co…

红米A2/A2+/POCO C51手机秒解BL+快速获取root权限+解谷歌锁刷机救砖教程

红米A2/A2/POCO C51手机是目前小米公司针对于国外用户的1个独立的品牌,或者和国内的红米手机都非常相似,几款手机由于硬件非常接近,我们这里将其放在一起和大家介绍而从他们的代号中我们可以得知,目前A2/POCO的代号为water&#x…