NO.A.0004——mysql/mariadb——make安装/配置

一、源码包下载:
1、地址:https://downloads.mariadb.org/mariadb/10.2.35/ 选择你要安装的版本;
在这里插入图片描述

下载源码包:mariadb-10.2.35.tar.gz包 //源码包比二进制包小好多73.9mb左右
2、安装环境:
mariadb版本:10.2.35
centos版本:centos7.6.1810
官方提示:不要在生产环境中使用beta和alpha版本的数据库;他们的主要功能一般是用来测试和排错的,不稳定,我们选择10.2.35系列的stable数据库

二、源码编译安装mariadb(官方建议使用cmake编译安装)
1、源码编译安装mariadb10.2.35的stable版本数据库:

//1、安装相关的软件依赖包:
[[email protected] ~]# 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
Installed:
  bison.x86_64 0:3.0.4-2.el7         bison-devel.x86_64 0:3.0.4-2.el7   
  boost-devel.x86_64 0:1.53.0-28.el7         cmake.x86_64 0:2.8.12.2-2.el7   
  gcc.x86_64 0:4.8.5-39.el7                  gcc-c++.x86_64 0:4.8.5-39.el7      
  gnutls-devel.x86_64 0:3.3.29-9.el7_6       libaio-devel.x86_64 0:0.3.109-13.el7   
  libarchive-devel.x86_64 0:3.1.2-14.el7_7   libcurl-devel.x86_64 0:7.29.0-57.el7_8.1 
  libevent-devel.x86_64 0:2.0.21-4.el7       libxml2-devel.x86_64 0:2.9.1-6.el7.4 
  ncurses-devel.x86_64 0:5.9-14.20130511.el7_4 openssl-devel.x86_64 1:1.0.2k-19.el7
  zlib-devel.x86_64 0:1.2.7-18.el7 
 //2、准备用户和数据的存放目录
[[email protected] ~]# useradd -r -s /sbin/nologin mysql     //创建mysql用户     
[[email protected] ~]# mkdir -pv /data/mysqldb             //创建数据存放目录
mkdir: created directory ‘/data’
mkdir: created directory ‘/data/mysqldb’
[[email protected] ~]# chown mysql.mysql /data/mysqldb  //把mysqldb目录的所有者,改为mysql
[[email protected] ~]# ll /data/
drwxr-xr-x 2 mysql mysql 6 Nov  7 17:07 mysqldb

2、解压并执行cmake

//3、解压、编译源码包;
[[email protected] ~]# tar -zxvf mariadb-10.2.35.tar.gz
[[email protected] ~]# cd mariadb-10.2.35/

[[email protected] mariadb-10.2.35]#cmake . \
-DCMAKE_INSTALL_PREFIX=/app/mysql \         //mysql安装程序的目录
-DMYSQL_DATADIR=/data/mysqldb/ \            //数据库数据存放目录
-DSYSCONFDIR=/etc \                         //指定配置文件所在目录
-DMYSQL_UNIX_ADDR=/app/mysql/mysql.sock \   //指定soket文件目录;默认情况下是在/tmp/mysql.sock
                                            //自定义目录后需要给该目录授予mysql用户读写执行权限
//执行如果出错,执行rm -f CMakeCache.txt文件

[[email protected] mariadb-10.2.35]# make  && make install 
[[email protected] mariadb-10.2.35]# make -j 4 && make install  
//-j4 与m-j8的意思就是多线程运行,
(线程的意思请参考操作系统)即4个进程去竞争多核cpu,或者8个线程去竞争cpu

3、cmake标准文件

cmake . \
-DCMAKE_INSTALL_PREFIX=/app/mysql \
-DMYSQL_DATADIR=/data/mysqldb/ \
-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=/tmp/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci

4、环境变量及启动脚本配置:

//4、准备环境变量:
[[email protected] ~]# echo PATH=/app/mysql/bin:$PATH > /etc/profile.d/mysql.sh
[[email protected] ~]# . /etc/profile.d/mysql.sh 

//5、生成数据库文件w
[[email protected] mariadb-10.2.35]# cd /app/mysql/
[[email protected] mysql]# scripts/mysql_install_db --datadir=/data/mysqldb/ --user=mysql  
    --basedir=/app/mysql                //执行之前确定mysql用户创建完成
ok

//6、准备配置文件:
[[email protected] mysql]# cp /app/mysql/support-files/my-huge.cnf /etc/my.cnf
cp: overwrite ‘/etc/my.cnf’? y
[[email protected] mysql]# vim /etc/my.cnf
socket          = /app/mysql/mysql.sock                 //指定sock文件地址

//7、准备自启动脚本:
[[email protected] mysql]# cp /app/mysql/support-files/mysql.server /etc/init.d/mysqld

5、启动服务:

//8、启动服务:
[[email protected] mysql]# chkconfig --add mysqld;service mysqld start
[[email protected] mysql]# systemctl  start  mysqld.service 
Starting mysqld (via systemctl):  Job for mysqld.service failed because the control process 
exited with error code. See "systemctl status mysqld.service" and "journalctl -xe" 
for details.
                                                           [FAILED]

//解决思路:查看日志:
[[email protected] mysqldb]# cat /data/mysqldb/localhost.localdomain.err 
                                        //查看日志报错;/app/mysql目录没有为用户mysql设置权限;
[ERROR] Can't start server : Bind on unix socket: Permission denied
[ERROR] Do you already have another mysqld server running on socket: /app/mysql/mysql.sock ?  
                                        //启动服务时会报错:因为没有读写权限:

//解决方案:
[[email protected] ~]# setfacl -R -m u:mysql:rwx /app/mysql/  
                                            //为/app/mysql目录设置mysql用户具有读写权限

[[email protected] mysqldb]# systemctl restart mysqld.service 

[[email protected] mysqldb]# mysql
Server version: 10.2.35-MariaDB-log
MariaDB [(none)]> show variables like "basedir";
+---------------+------------+
| Variable_name | Value      |
+---------------+------------+
| basedir       | /app/mysql |

//9、设置开机自启动
[[email protected] ~]# cp /app/mysql/support-files/mysql.server /etc/init.d/mysqld
[[email protected] ~]# chkconfig --add mysqld
[[email protected] ~]# chkconfig --list
mysqld          0:off   1:off   2:on    3:on    4:on    5:on    6:off

6、设置root账号口令

//10、为mysql数据库程序设置root账号口令:
[[email protected] ~]# mysql_secure_installation 

猜你喜欢

转载自blog.51cto.com/15005403/2552279