linux进阶-编译安装mariadb-10.2

编译安装mariadb数据库


在这里插入图片描述

大家好,我们又见面了!
今天分享简单的编译安装mariadb数据库

安装相关依赖包

[root@centos7 ~]# yum install bison bison-devel zlib-devel libcurl-devel libarchive-devel boostdevel gcc gcc-c++ cmake ncurses-devel gnutls-devel libxml2-devel openssldevel libevent-devel libaio-devel ✅

创建用户和数据目录

[root@centos7 ~]# useradd -r -s /sbin/nologin -d /data/mysql mysql ✅

创建数据库目录

[root@centos7 ~]# mkdir /data/mysql ✅
[root@centos7 ~]# chown mysql.mysql /data/mysql/ ✅

编译安装说明

利用cmake编译,而利用传统方法,cmake的重要特性之一是其独立于源码(out-of-source)的编译功能,
即编译工作可以在另一个指定的目录中而非源码目录中进行,这可以保证源码目录不受任何一次编译的
影响,因此在同一个源码树上可以进行多次不同的编译,如针对于不同平台编译
编译选项:https://dev.mysql.com/doc/refman/5.7/en/source-configuration-options.html

下载并解压缩源码包

[root@centos7 data]# tar xvf mariadb-10.2.29.tar.gz ✅
此处省略解压缩内容

源码编译安装mariadb

[root@centos7 data]# cd mariadb-10.2.29/
[root@centos7 mariadb-10.2.29]#

[root@centos7 mariadb-10.2.29]# cmake . \ ✅
> -DCMAKE_INSTALL_PREFIX=/app/mysql \
> -DMYSQL_DATADIR=/data/mysql/ \
> -DSYSCONFDIR=/etc/ \
> -DMYSQL_USER=mysql \
> -DWITH_INNOBASE_STORAGE_ENGINE=1 \
> -DWITH_ARCHIVE_STORAGE_ENGINE=1 \
> -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
> -DWITH_PARTITION_STORAGE_ENGINE=1 \
> -DWITHOUT_MROONGA_STORAGE_ENGINE=1 \
> -DWITH_DEBUG=0 \
> -DWITH_READLINE=1 \
> -DWITH_SSL=system \
> -DWITH_ZLIB=system \
> -DWITH_LIBWRAP=0 \
> -DENABLED_LOCAL_INFILE=1 \
> -DMYSQL_UNIX_ADDR=/data/mysql/mysql.sock \
> -DDEFAULT_CHARSET=utf8 \
> -DDEFAULT_COLLATION=utf8_general_ci

[root@centos7 mariadb-10.2.29]# echo $? ✅
0

[root@centos7 mariadb-10.2.29]# yum search 关键字 #如果报错用此命令查找关键字
[root@centos7 mariadb-10.2.29]# yum install 包-devel #使用此命令安装缺失的包
[root@centos7 mariadb-10.2.29]# make -j 4 && make install ✅

❗❗❗提示:如果出错,记得执行rm -f CMakeCache.txt文件后,重新编译❗❗❗

准备环境变量

[root@centos7 mariadb-10.2.29]# echo 'PATH=/app/mysql/bin:$PATH' > /etc/profile.d/mysql.sh #创建变量文件 ✅
[root@centos7 mariadb-10.2.29]# . /etc/profile.d/mysql.sh #生效文件 ✅

生成数据库文件

[root@centos7 mariadb-10.2.29]# cd /app/mysql/ 
[root@centos7 mysql]# scripts/mysql_install_db --datadir=/data/mysql/ --user=mysql ✅

准备配置文件

[root@centos7 mysql]# cp /app/mysql/support-files/my-huge.cnf /etc/my.cnf ✅

准备启动脚本,并启动服务

[root@centos7 mysql]# cp /app/mysql/support-files/mysql.server /etc/init.d/mysqld ✅
[root@centos7 mysql]# chkconfig --add mysqld 
[root@centos7 mysql]# service mysqld start #启东服务 ✅

安全初始化/加固

[root@centos7-maridb mysql]# 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
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none): 
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set 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] y
 ... Success!

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
 - 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@centos7 mysql]# mysql -uroot -p ✅
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 21
Server version: 10.2.29-MariaDB-log 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)]>     #看到这个界面表示登录成功
看到这条信息,首先谢谢您😘其次表示本次分享到这就完全结束了,欢迎下次光临!(~ ̄▽ ̄)~
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在Docker中使用docker-compose安装MariaDB 10.5,你可以按照以下步骤进行操作: 1. 确保你的系统已经安装了Docker和docker-compose。如果没有安装,你可以参考官方文档进行安装。 2. 创建一个新的目录,并在该目录下创建一个名为`docker-compose.yml`的文件。 3. 在`docker-compose.yml`文件中,添加以下内容: ```yaml version: '3' services: mariadb: image: mariadb:10.5 restart: always environment: MYSQL_ROOT_PASSWORD: your_root_password volumes: - ./data:/var/lib/mysql ``` 在上面的配置中,我们使用了MariaDB 10.5的官方Docker镜像,并设置了MySQL的root密码。你需要将`your_root_password`替换为你自己的密码。 此外,我们还将MariaDB的数据目录`/var/lib/mysql`映射到了本地的`./data`目录,这样可以确保数据持久化。 4. 保存并关闭`docker-compose.yml`文件。 5. 打开终端,进入到包含`docker-compose.yml`文件的目录。 6. 运行以下命令启动MariaDB容器: ``` docker-compose up -d ``` 这将下载并启动MariaDB容器。第一次启动可能需要一些时间来完成初始化。 7. 当容器启动成功后,你可以使用任何MySQL客户端连接到MariaDB。只需使用主机名`localhost`,端口号为`3306`,用户名为`root`,密码为你在`docker-compose.yml`中设置的密码。 这样,你就成功使用docker-compose安装MariaDB 10.5。希望对你有所帮助!如果你有其他问题,请随时提问。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值