linux进阶-编译安装mariadb-10.2

编译安装mariadb数据库

文章目录

  • 编译安装mariadb数据库
  • 安装相关依赖包
  • 创建用户和数据目录
  • 创建数据库目录
  • 编译安装说明
  • 下载并解压缩源码包
  • 源码编译安装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)]>     #看到这个界面表示登录成功
看到这条信息,首先谢谢您其次表示本次分享到这就完全结束了,欢迎下次光临!(~ ̄▽ ̄)~

你可能感兴趣的:(编译安装)