MariaDB 源码编译安装

1、安装编译所需软件包

yum -y install 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

2、准备用户和数据目录

useradd -r -s /sbin/nologin mysql
mkdir -p /data/mysql
chown -R mysql:mysql /data
tar xvf mariadb-10.4.12.tar.gz

3、 cmake 编译安装

cmake的重要特性之一是其独立于源码(out-of-source)的编译功能,即编译工作可以在另一个指定的目录中而非源码目录中进行,这可以保证源码目录不受任何一次编译的影响,因此在同一个源码树上可以进行多次不同的编译,如针对于不同平台编译

cd mariadb-10.4.12/

cmake . \
-DCMAKE_INSTALL_PREFIX=/usr/local/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 [cpunumber] && make install
提示:如果出错,执行rm -f CMakeCache.txt

4、修改权限

chown -R mysql:mysql  /usr/local/mysql/

5、 准备配置文件

[root@centos72-test1 mysql]# cat /etc/my.cnf
[mysql]
# 设置mysql客户端默认字符集
default-character-set=utf8
[mysqld]
#skip-name-resolve
# 设置3306端口
port=3306
# 设置mysql的安装目录
basedir=/usr/local/mysql
# 设置mysql数据库的数据的存放目录
datadir=/data/mysql
# 允许最大连接数
max_connections=2000
log-error=/var/log/mysqld.log
#pid-file=/var/run/mysqld/mysqld.pid
# 服务端使用的字符集默认为8比特编码的latin1字符集
character-set-server=utf8
# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB
lower_case_table_names=1
innodb_buffer_pool_size = 1G # (adjust value here, 50%-70% of total RAM)
innodb_log_file_size = 256M
innodb_flush_log_at_trx_commit = 1 # may change to 2 or 0
innodb_flush_method = O_DIRECT
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
-------------------
[root@centos72-test1 mysql]# touch /var/log/mysqld.log
[root@centos72-test1 mysql]# chown mysql:mysql /var/log/mysqld.log

6、创建数据库文件

cd /usr/local/mysql/
./scripts/mysql_install_db --datadir=/data/mysql --user=mysql

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

Centos6
-------------
cp ./support-files/mysql.server /etc/rc.d/init.d/mysqld
chkconfig --add mysqld
service mysqld start
-------------
Centos7
-------------
#vim /usr/lib/systemd/system/mysql.service

[Unit]
Description=MySQL Server
Documentation=man:mysqld(8)
Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target

[Install]
WantedBy=multi-user.target

[Service]
User=mysql
Group=mysql
ExecStart=/usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf
LimitNOFILE = 5000
#Restart=on-failure
#RestartPreventExitStatus=1
#PrivateTmp=false
----------
[root@centos72-test1 mysql]# systemctl  start mysql
[root@centos72-test1 mysql]# systemctl  status mysql
● mysql.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysql.service; disabled; vendor preset: disabled)
   Active: active (running) since Wed 2020-05-06 15:31:14 CST; 6s ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
Main PID: 3462 (mysqld)

[root@centos72-test1 mysql]# systemctl  enable mysql
Created symlink from /etc/systemd/system/multi-user.target.wants/mysql.service to /usr/lib/systemd/system/mysql.service.

8、添加环境变量

echo 'PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
. /etc/profile.d/mysql.sh
-----------------
[root@centos72-test1 local]# mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 8
Server version: 10.4.12-MariaDB MariaDB Server

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)]> quit
Bye

9、安全初始化

/usr/local/mysql/bin/mysql_secure_installation

Note:执行完安全初始化脚本 之后,如果发现 直接执行mysql 依旧可以登录,此时再次修改下密码即可
Unix Socke插件认证忽略密码

[root@centos72-test1 ~]# mysqladmin -u root -p  password '123456'

MariaDB [mysql]> select user,host,password,plugin from user;
+-------+-----------+-------------------------------------------+-----------------------+
| User  | Host      | Password                                  | plugin                |
+-------+-----------+-------------------------------------------+-----------------------+
| root  | localhost | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 | mysql_native_password |
| mysql | localhost | invalid                                   | mysql_native_password |
+-------+-----------+-------------------------------------------+-----------------------+
2 rows in set (0.001 sec)

你可能感兴趣的:(Mariadb)