0、首先检查是否已经安装过mysql:

    # rpm -qa | grep mysql

    # rpm -qa | grep mariadb

有的话就卸载掉以前安装的mysql,mariadb:

    # rpm -e --nodeps xxx(xxx是搜索结果)

 

1、安装依赖库

[root@localhost ~]# yum -y install readline-devel zlib-devel openssl-devel libaio-devel

 2、cmake下载地址https://cmake.org/download/ ;mariadb-10.4.12下载地址https://downloads.mariadb.org/mariadb/10.4.12/  上传至 /usr/src下

 

 

 

 3、安装cmake

[root@localhost ~]# cd /usr/src/ 
[root@localhost src]# tar -zxvf cmake-3.17.0.tar.gz
[root@localhost src]# cd cmake-3.17.0
[root@localhost cmake-3.17.0]# ./configure
[root@localhost cmake-3.17.0]# gmake && gmake install

4、安装目录设为 /usr/local/mysql,数据目录/data/mysql ,建立用户、目录,赋予mysql用户权限

[root@localhost cmake-3.17.0]# groupadd -r mysql
[root@localhost cmake-3.17.0]# useradd -g mysql -s /sbin/nologin mysql
[root@localhost cmake-3.17.0]# mkdir /usr/local/mysql/
[root@localhost cmake-3.17.0]# mkdir -p /data/mysql/
[root@localhost cmake-3.17.0]# chown -R mysql:mysql /data/mysql

5、解压mariadb,编译安装mariadb 

[root@localhost src]# tar -zxvf mariadb-10.4.12.tar.gz
[root@localhost src]# cd mariadb-10.4.12
[root@localhost mariadb-10.4.12]# cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/data/mysql/ -DSYSCONFDIR=/etc -DWITHOUT_TOKUDB=1 -DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci

如果万一执行中有了错误,可以执行: rm -f CMakeCache.txt 删除编译缓存,让指令重新执行.

[root@localhost mariadb-10.4.12]# make && make install

6、为/usr/local/mysql 设置所属组,用户。在/usr/local/mysql 生成数据库,把/usr/local/mysql/support-files服务脚本复制到 /etc/init.d/目录下改名为mysqld

[root@localhost mariadb-10.4.12]# cd /usr/local/mysql/
[root@localhost mysql]# chown -R mysql:mysql .
[root@localhost mysql]# scripts/mysql_install_db --datadir=/data/mysql --user=mysql
[root@localhost mysql]# chown -R root .
[root@localhost mysql]#  cp support-files/mysql.server /etc/init.d/mysqld

7、加入chkconfig管理,设置开机自动启动

[root@localhost mysql]# chkconfig --add mysqld
[root@localhost mysql]# chkconfig mysqld on

8、添加环境变量,并查看PATH

[root@localhost mysql]# echo 'PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
[root@localhost mysql]# source /etc/profile.d/mysql.sh
[root@localhost mysql]# echo $PATH

9、启动服务 

[root@localhost mysql]# systemctl start mysqld

10、运行安全脚本,并设置密码

[root@localhost mysql]# mysql_secure_installation

11、登录mariadb服务器

[root@localhost mysql]# mysql -u root -p
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 19
Server version: 10.4.12-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)]>

  

 

 

posted on 2020-04-03 15:09  草根920  阅读(1089)  评论(0编辑  收藏  举报