在centos7.3, centos7.6上都试过了,都可以安装成功,并隐藏版本号。
下载相关依赖:https://download.csdn.net/download/paincupid/11388112
1、安装gcc等依赖
yum install openssl openssl-devel ncurses ncurses-devel bison bison-devel jemalloc jemalloc-devel centos-release-scl devtoolset-7 gcc gcc-c++
2、安装cmake
cmake版本要高于3.10
https://cmake.org/download/
./bootstrap &&
gmake &&
gmake install
查看编译后的cmake版本
/usr/local/bin/cmake --version
如果存在旧版本,移除原来的cmake版本并新建软链接
yum remove cmake -y
ln -s /usr/local/bin/cmake /usr/bin/
cmake --version
如果万一执行中有了错误,可以执行:rm -f CMakeCache.txt
删除编译缓存
3、安装libevent
libevent-2.1.10
./configure --prefix=/usr --disable-static &&
make
make install
2、安装C++高版本
MariaDB 编译 TokuDB 引擎时会用到 C++11 标准,系统里 GCC 最高版本 4.8.5 是支持 C++11 标准的,可就算指定了 -DCMAKE_CXX_FLAGS=-std=c++11 也不行。手动编译更高版本的 GCC 又太麻烦,这里直接安装了 devtoolset-7,当然你禁用 TokuDB 引擎也无可厚非。
yum install centos-release-scl devtoolset-7
gcc --version
// gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-28)
// Copyright © 2015 Free Software Foundation, Inc.
scl enable devtoolset-7 bash
// or
. /opt/rh/devtoolset-7/enable
gcc --version
// gcc (GCC) 7.3.1 20180303 (Red Hat 7.3.1-5)
scl enable devtoolset-7 bash 命令重启后会失效
1、下载mariadb
下载地址:
https://downloads.mariadb.org/
https://downloads.mariadb.org/interstitial/mariadb-10.4.6/source/mariadb-10.4.6.tar.gz
2、解压文件
tar -zxvf mariadb-10.4.6.tar.gz
cd mariadb-10.4.6
3、修改版本号
vi VERSION
修改为
MYSQL_VERSION_MAJOR=101
MYSQL_VERSION_MINOR=42
MYSQL_VERSION_PATCH=63
SERVER_MATURITY=stable
4、为mariadb创建用户组和用户
groupadd -g 41 mysql &&
useradd -c "MySQL Server" -d /srv/mysql -g mysql -s /bin/false -u 41 mysql
5、安装mariadb
sed -i "s@data/test@\${INSTALL_MYSQLTESTDIR}@g" sql/CMakeLists.txt &&
mkdir build &&
cd build &&
cmake -DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX=/usr \
-DINSTALL_DOCDIR=share/doc/mariadb-10.4.6 \
-DINSTALL_DOCREADMEDIR=share/doc/mariadb-10.4.6 \
-DINSTALL_MANDIR=share/man \
-DINSTALL_MYSQLSHAREDIR=share/mysql \
-DINSTALL_MYSQLTESTDIR=share/mysql/test \
-DINSTALL_PLUGINDIR=lib/mysql/plugin \
-DINSTALL_SBINDIR=sbin \
-DINSTALL_SCRIPTDIR=bin \
-DINSTALL_SQLBENCHDIR=share/mysql/bench \
-DINSTALL_SUPPORTFILESDIR=share/mysql \
-DMYSQL_DATADIR=/srv/mysql \
-DMYSQL_UNIX_ADDR=/run/mysqld/mysqld.sock \
-DWITH_EXTRA_CHARSETS=complex \
-DWITH_EMBEDDED_SERVER=ON \
-DSKIP_TESTS=ON \
-DTOKUDB_OK=0 \
.. &&
make
-DCMAKE_INSTALL_PREFIX= 指向mysql安装目录
-DINSTALL_SBINDIR=sbin 指向可执行文件目录(prefix/sbin)
-DMYSQL_DATADIR=/var/lib/mysql 指向mysql数据文件目录(/var/lib/mysql)
-DSYSCONFDIR=/etc/mysql 指向mysql配置文件目录(/etc/mysql)
-DINSTALL_PLUGINDIR=lib/mysql/plugin 指向插件目(prefix/lib/mysql/plugin)
-DINSTALL_MANDIR=share/man 指向man文档目录(prefix/share/man)
-DINSTALL_SHAREDIR=share 指向aclocal/mysql.m4安装目录(prefix/share)
-DINSTALL_LIBDIR=lib/mysql 指向对象代码库目录(prefix/lib/mysql)
-DINSTALL_INCLUDEDIR=include/mysql 指向头文件目录(prefix/include/mysql)
-DINSTALL_INFODIR=share/info 指向info文档存放目录(prefix/share/info)
prefix官方推荐设为/usr
结果
Scanning dependencies of target SYM_mariadb-fix-extensions
[100%] mklink mysql_fix_extensions -> mariadb-fix-extensions
[100%] Built target SYM_mariadb-fix-extensions
Scanning dependencies of target symlink_wsrep_sst_rsync
[100%] Generating wsrep_sst_rsync_wan
[100%] Built target symlink_wsrep_sst_rsync
Scanning dependencies of target SYM_mariadb-secure-installation
[100%] mklink mysql_secure_installation -> mariadb-secure-installation
[100%] Built target SYM_mariadb-secure-installation
Scanning dependencies of target SYM_mariadb-access
[100%] mklink mysqlaccess -> mariadb-access
[100%] Built target SYM_mariadb-access
Scanning dependencies of target SYM_mariadb-hotcopy
[100%] mklink mysqlhotcopy -> mariadb-hotcopy
[100%] Built target SYM_mariadb-hotcopy
Scanning dependencies of target SYM_mariadb-convert-table-format
[100%] mklink mysql_convert_table_format -> mariadb-convert-table-format
[100%] Built target SYM_mariadb-convert-table-format
Scanning dependencies of target SYM_mariadb-dumpslow
[100%] mklink mysqldumpslow -> mariadb-dumpslow
[100%] Built target SYM_mariadb-dumpslow
Scanning dependencies of target SYM_mariadb-setpermission
[100%] mklink mysql_setpermission -> mariadb-setpermission
[100%] Built target SYM_mariadb-setpermission
Scanning dependencies of target SYM_mariadb-install-db
[100%] mklink mysql_install_db -> mariadb-install-db
[100%] Built target SYM_mariadb-install-db
Scanning dependencies of target SYM_mariadbd-multi
[100%] mklink mysqld_multi -> mariadbd-multi
[100%] Built target SYM_mariadbd-multi
Scanning dependencies of target SYM_mariadb-find-rows
[100%] mklink mysql_find_rows -> mariadb-find-rows
[100%] Built target SYM_mariadb-find-rows
Scanning dependencies of target SYM_mariadbd-safe
[100%] mklink mysqld_safe -> mariadbd-safe
[100%] Built target SYM_mariadbd-safe
Scanning dependencies of target mariadb-pp
[100%] Generating mariadb.pp
/usr/bin/checkmodule: loading policy configuration from /root/mariadb-10.4.6/support-files/policy/selinux/mariadb.te
/usr/bin/checkmodule: policy configuration loaded
/usr/bin/checkmodule: writing binary representation (version 19) to /root/mariadb-10.4.6/build/support-files/CMakeFiles/mariadb-pp.dir/mariadb.mod
[100%] Built target mariadb-pp
[root@localhost build]#
make install
6、创建文件/etc/mysql/my.cnf
install -v -dm 755 /etc/mysql &&
cat > /etc/mysql/my.cnf << "EOF"
# Begin /etc/mysql/my.cnf
# The following options will be passed to all MySQL clients
[client]
#password = your_password
port = 3306
socket = /run/mysqld/mysqld.sock
# The MySQL server
[mysqld]
port = 3306
socket = /run/mysqld/mysqld.sock
datadir = /srv/mysql
skip-external-locking
key_buffer_size = 16M
max_allowed_packet = 1M
sort_buffer_size = 512K
net_buffer_length = 16K
myisam_sort_buffer_size = 8M
# Don't listen on a TCP/IP port at all.
skip-networking
# required unique id between 1 and 2^32 - 1
server-id = 1
# Uncomment the following if you are using BDB tables
#bdb_cache_size = 4M
#bdb_max_lock = 10000
# InnoDB tables are now used by default
innodb_data_home_dir = /srv/mysql
innodb_log_group_home_dir = /srv/mysql
# All the innodb_xxx values below are the default ones:
innodb_data_file_path = ibdata1:12M:autoextend
# You can set .._buffer_pool_size up to 50 - 80 %
# of RAM but beware of setting memory usage too high
innodb_buffer_pool_size = 128M
innodb_log_file_size = 48M
innodb_log_buffer_size = 16M
innodb_flush_log_at_trx_commit = 1
innodb_lock_wait_timeout = 50
[mysqldump]
quick
max_allowed_packet = 16M
[mysql]
no-auto-rehash
# Remove the next comment character if you are not familiar with SQL
#safe-updates
[isamchk]
key_buffer = 20M
sort_buffer_size = 20M
read_buffer = 2M
write_buffer = 2M
[myisamchk]
key_buffer_size = 20M
sort_buffer_size = 20M
read_buffer = 2M
write_buffer = 2M
[mysqlhotcopy]
interactive-timeout
# End /etc/mysql/my.cnf
EOF
7、初始化数据库以及修改所有者权限
mysql_install_db --basedir=/usr --datadir=/srv/mysql --user=mysql &&
chown -R mysql:mysql /srv/mysql
如果执行的报以下错误
[root@localhost build]# mysql_install_db --basedir=/usr --datadir=/srv/mysql --user=mysql &&
> chown -R mysql:mysql /srv/mysql
chown: cannot access ‘/auth_pam_tool_dir’: No such file or directory
Cannot change ownership of the '/auth_pam_tool_dir' directory
to the 'mysql' user. Check that you have the necessary permissions and try again.
解决方案:可以复制一份mysql_install_db
替换它,再执行上面的命令。mysql_install_db
在script
目录下。mysql_install_db
在分享的下载包中。
cd /usr/bin
mv mysql_install_db mysql_install_db_bak
cp /root/mysql_install_db /usr/bin
执行成功,会有以下提示
[root@localhost bin]# mysql_install_db --basedir=/usr --datadir=/srv/mysql --user=mysql &&
> chown -R mysql:mysql /srv/mysql
Installing MariaDB/MySQL system tables in '/srv/mysql' ...
2019-07-17 7:42:53 0 [Note] /usr/sbin/mysqld (mysqld 101.42.63-MariaDB) starting as process 6129 ...
OK
Filling help tables...
2019-07-17 7:42:53 0 [Note] /usr/sbin/mysqld (mysqld 101.42.63-MariaDB) starting as process 6136 ...
OK
To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system
PLEASE REMEMBER TO SET A PASSWORD FOR THE MariaDB root USER !
To do so, start the server, then issue the following commands:
'/usr/bin/mysqladmin' -u root password 'new-password'
'/usr/bin/mysqladmin' -u root -h localhost.localdomain password 'new-password'
Alternatively you can run:
'/usr/bin/mysql_secure_installation'
which will also give you the option of removing the test
databases and anonymous user created by default. This is
strongly recommended for production servers.
See the MariaDB Knowledgebase at http://mariadb.com/kb or the
MySQL manual for more instructions.
You can start the MariaDB daemon with:
cd '/usr' ; /usr/bin/mysqld_safe --datadir='/srv/mysql'
You can test the MariaDB daemon with mysql-test-run.pl
cd '/usr/mysql-test' ; perl mysql-test-run.pl
Please report any problems at http://mariadb.org/jira
The latest information about MariaDB is available at http://mariadb.org/.
You can find additional information about the MySQL part at:
http://dev.mysql.com
Consider joining MariaDB's strong and vibrant community:
https://mariadb.org/get-involved/
8、启动mysql
cp /root/mariadb-10.4.6/build/support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
update-rc.d mysqld defaults
chkconfig --add mysqld
/etc/init.d/mysqld restart
systemctl status mysqld
9、为root用户设置密码
'/usr/bin/mysqladmin' -u root password 'root'
10、登陆
[root@localhost bin]# mysql -uroot -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 10
Server version: 101.42.63-MariaDB 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)]> select version();
+-------------------+
| version() |
+-------------------+
| 101.42.63-MariaDB |
+-------------------+
1 row in set (0.000 sec)
MariaDB [(none)]>
参考:
http://www.linuxfromscratch.org/blfs/view/svn/server/mariadb.html