#私藏项目实操分享# 编译安装Mariadb,并启动后可以正常登录

但使书种多,会有岁稔时。这篇文章主要讲述#私藏项目实操分享# 编译安装Mariadb,并启动后可以正常登录相关的知识,希望能为你提供帮助。
查看系统版本

$ cat /etc/redhat-release
CentOS Linux release 7.9.2009 (Core)

安装依赖包
$ yum install -y bison bison-devel zlib-devel libcurl-devel libarchive-devel boost-devel gcc gcc-c++ cmake ncurses-devel gnutls-devel libxml2-devel openssl-devel libevent-devel libaio-devel

准备用户,不能登录系统
$ cd /usr/local/src/
$ useradd –r –s /sbin/nologin –d /data/mysql/ mysql

准备数据目录并授权
$ mkdir /data/mysql
$ chown mysql.mysql /data/mysql

准备安装包,这里用清华大学镜像站的源码包
$ wget https://mirrors.tuna.tsinghua.edu.cn/mariadb/mariadb-10.2.41/source/mariadb-10.2.41.tar.gz --no-check-certificate

解压安装包
$ tar xvf mariadb-10.2.41.tar.gz

【#私藏项目实操分享# 编译安装Mariadb,并启动后可以正常登录】编译安装,注意数据目录下必须要有CMakeCache.txt文件,如果一下编译过程报错,删除此文件重来
$ cd mariadb-10.2.41
$ 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
$ make -j 4
$ make install

准备环境变量
$ echo PATH=/app/mysql/bin:$PATH > /etc/profile.d/mysql.sh
$ . /etc/profile.d/mysql.sh

生成数据库文件
$ cd /app/mysql
$ scripts/mysql_install_db --datadir=/data/mysql/ --user=mysql

准备配置文件
$ cp /etc/my.cnf /etc/my.cnf.bak
$ cp /app/mysql/support-files/my-huge.cnf /etc/my.cnf

准备启动脚本
$ cp /app/mysql/support-files/mysql.server /etc/init.d/mysqld

启动服务
$ chkconfig --add mysqld
$ service mysqld start

测试进入数据库
$ mysql
Welcome to the MariaDB monitor.Commands end with ; or \\g.
Your MariaDB connection id is 12
Server version: 10.2.41-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)]> show databases;
+--------------------+
| Database|
+--------------------+
| information_schema |
| mysql|
| performance_schema |
| test|
+--------------------+
4 rows in set (0.00 sec)

MariaDB [(none)]> quit
Bye



    推荐阅读