1、卸载系统自带的MariaDB数据库
# find -H /etc/ | grep my.cnf
# rpm -qa|grep mariadb-libs
# rpm -e --nodeps mariadb-libs-5.5.52-1.el7.x86_64
2、安装相关依赖包
# yum install cmake openssl-devel zlib-devel ncurses-devel -y
# yum install readline-devel openssl-devel libaio-devel -y
3、创建MariaDB安装目录、数据库存放目录、建立用户和目录
# mkdir -p /usr/local/mysql #创建maria安装目录
# mkdir -pv /app/mysql/{data,bin_log,run,log,tmp} #创建数据库存放目录
# groupadd -r mysql #创建mysql系统用户组及用户
# chown -R mysql:mysql /app/mysql/ #添加权限
4、执行编译安装
# tar -zvxf mariadb-10.2.13.tar.gz
# cd mariadb-10.2.13
# 开始编译
# cmake . \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/app/mysql/data \
-DSYSCONFDIR=/etc \
-DWITHOUT_TOKUDB=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STPRAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWIYH_READLINE=1 \
-DWIYH_SSL=system \
-DVITH_ZLIB=system \
-DWITH_LOBWRAP=0 \
-DMYSQL_UNIX_ADDR=/app/mysql/tmp/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci
注意:如果万一执行中有了错误,可以执行: rm -f CMakeCache.txt 删除编译缓存,让指令重新执行,否则每次读取这个文件,命令修改正确也是报错
# make && make install # 安装
------执行完成也就是安装完成了------------
5、配置MariaDB
# cd /usr/local/mysql/ #进入mysql安装目录分别执行下面命令:
# chown -R mysql:mysql .
# scripts/mysql_install_db --datadir=/app/mysql/data --user=mysql
# chown -R root .
#cp support-files/mysql.server /etc/init.d/mysqld
# cp support-files/my-large.cnf /etc/my.cnf
# grep -v ^# /etc/my.cnf | grep -v ^$ #查看my.cnf配置
6、初始化MariaDB
# ./bin/mysql_secure_installation #输入你的新密码,匿名用户,禁止root远程登录,是否删除test数据库。
----------------------------------------------
#由于一开始安装MariaDB数据库后, root用户默认密码为空, 所以只需要按Enter键
Enter current password for root (enter for none):
#是否设置root用户的新密码
Set root password? [Y/n] y
#录入新密码
New password:
#确认新密码
Re-enter new password:
#是否删除匿名用户,生产环境建议删除
Remove anonymous users? [Y/n] y
#是否禁止root远程登录,根据自己的需求选择
Disallow root login remotely? [Y/n] n
#是否删除test数据库
Remove test database and access to it? [Y/n] y
#是否重新加载权限表
Reload privilege tables now? [Y/n] y
-------------------------------------------------
#systemctl start mysqld # 启动MYSQL服务
# ln -sv /usr/local/mysql/bin/mysql /usr/bin/ #添加软链接Mysql
# mysql -uroot -p #连接数据库
安装配置完成。
==========================================================
编译注解:
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \ # 指定安装的根目录
-DMYSQL_DATADIR=/app/mysql/data \ # 数据存储目录
-DTMPDIR=/app/mysql/tmp \ # 临时文件存放目录
-DMYSQL_UNIX_ADDR=/app/mysql/run/mysqld.sock \ # UNIX socket文件
-DSYSCONFDIR=/etc \ # 配置文件存放目录,具体的配置文件是/etc/my.cnf
-DWITH_MYISAM_STORAGE_ENGINE=1 \ # Myisam 引擎支持
-DWITH_INNOBASE_STORAGE_ENGINE=1 \ # innoDB 引擎支持
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \ # ARCHIVE 引擎支持
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \ # BLACKHOLE 引擎支持
-DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \ # PERFSCHEMA 引擎支持
-DWITH_FEDERATED_STORAGE_ENGINE=1 \ # FEDERATEDX 引擎支持
-DWITH_TOKUDB_STORAGE_ENGINE=1 \ # TOKUDB 引擎支持
-DWITH_XTRADB_STORAGE_ENGINE=1 \ # XTRADB 引擎支持
-DWITH_ARIA_STORAGE_ENGINE=1 \ # ARIA 引擎支持
-DWITH_PARTITION_STORAGE_ENGINE=1 \ # PARTITION 引擎支持
-DWITH_SPHINX_STORAGE_ENGINE=1 \ # SPHINX 引擎支持
-DWITH_READLINE=1 \ # readline库
-DMYSQL_TCP_PORT=3306 \ # TCP/IP端口
-DENABLED_LOCAL_INFILE=1 \ # 启用加载本地数据
-DWITH_EXTRA_CHARSETS=all \ # 扩展支持编码 ( all | utf8,gbk,gb2312 | none )
-DEXTRA_CHARSETS=all \ # 扩展字符支持
-DDEFAULT_CHARSET=utf8 \ # 默认字符集
-DDEFAULT_COLLATION=utf8_general_ci \ # 默认字符校对
-DCMAKE_EXE_LINKER_FLAGS='-ljemalloc' \ # Jemalloc内存管理库
-DWITH_SAFEMALLOC=OFF \ # 关闭默认内存管理
-DWITH_DEBUG=0 \ # 关闭调试模式
-DENABLE_PROFILING=1 \ # 启用性能分析功能
-DWITH_SSL=system \ # 使用系统上的自带的SSL库
-DWITH_ZLIB=system \ # 使用系统上的自带的zlib库
-DWITH_LIBWRAP=0 # 禁用libwrap库
==========================================================
2、故障处理:
2017-10-20 11:18:40 140526456133696 [Note] /usr/local/mysql/bin/mysqld (mysqld 10.2.7-MariaDB-log) starting as process 7649 ...
2017-10-20 11:18:40 140526456133696 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2017-10-20 11:18:40 140526456133696 [Note] InnoDB: Uses event mutexes
2017-10-20 11:18:40 140526456133696 [Note] InnoDB: Compressed tables use zlib 1.2.7
2017-10-20 11:18:40 140526456133696 [Note] InnoDB: Using Linux native AIO
2017-10-20 11:18:40 140526456133696 [Note] InnoDB: Number of pools: 1
2017-10-20 11:18:40 140526456133696 [Note] InnoDB: Using SSE2 crc32 instructions
2017-10-20 11:18:40 140526456133696 [ERROR] mysqld: Can't create/write to file '/usr/local/mysql/tmp/ibvlB0yL' (Errcode: 2 "No such file or directory")
2017-10-20 11:18:40 140526456133696 [ERROR] InnoDB: Unable to create temporary file; errno: 2
2017-10-20 11:18:40 140526456133696 [ERROR] mysqld: Can't create/write to file '/usr/local/mysql/tmp/ibJ0tHZ9' (Errcode: 2 "No such file or directory")
2017-10-20 11:18:40 140526456133696 [ERROR] InnoDB: Unable to create temporary file; errno: 2
2017-10-20 11:18:40 140526456133696 [ERROR] mysqld: Can't create/write to file '/usr/local/mysql/tmp/ibOCtoqy' (Errcode: 2 "No such file or directory")
2017-10-20 11:18:40 140526456133696 [ERROR] InnoDB: Unable to create temporary file; errno: 2
2017-10-20 11:18:40 140526456133696 [ERROR] InnoDB: Plugin initialization aborted with error Generic error
2017-10-20 11:18:40 140526456133696 [Note] InnoDB: Starting shutdown...
2017-10-20 11:18:40 140526456133696 [ERROR] Plugin 'InnoDB' init function returned error.
2017-10-20 11:18:40 140526456133696 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
2017-10-20 11:18:40 140526456133696 [Note] Plugin 'FEEDBACK' is disabled.
2017-10-20 11:18:40 140526456133696 [ERROR] Unknown/unsupported storage engine: InnoDB
2017-10-20 11:18:40 140526456133696 [ERROR] Aborting
171020 11:18:40 mysqld_safe mysqld from pid file /data/mysql/data/linux-node3.example.com.pid ended
解决方法:
在my.cnf配置文件中查找”[mysqld]“,在其下添加一行:
tmpdir=%你想指定的MySQL临时文件目录(例如 D:temp)%