微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Centos8 二进制安装MariaDB-10.2.31

1、准备用户并创建存放数据库文件

[root@centos7 ~]#groupadd -r -g 306 MysqL
[root@centos7 ~]#useradd -r -g 306 -u 306 -d /data/MysqL  MysqL
[root@centos7 ~]#mkdir /data/MysqL

2、下载安装包并解压到指定的路径

[root@centos7 ~]#tar xf mariadb-10.2.31-linux-systemd-x86_64.tar.gz -C /usr/local/
[root@centos7 ~]#cd /usr/local/
#####创建软链接是为了后续升级数据库方便
[root@centos7 local]#ln -s mariadb-10.2.31-linux-systemd-x86_64/ MysqL

3、数据库文件初始化

####注意:要和/etc/init.d/MysqLd里面的路径保持一致
[root@centos7 ~]#/usr/local/MysqL/scripts/MysqL_install_db --datadir=/data/MysqL --basedir=/usr/local/MysqL --user=MysqL

4、给相关文件目录赋予权限

[root@centos7 ~]#chown -R MysqL.MysqL /data/MysqL
[root@centos7 ~]#chown -R MysqL.MysqL /usr/local/mariadb* /usr/local/MysqL/

5、配置启动数据库配置文件

[root@centos7 ~]#cat /etc/my.cnf
[MysqLd]
datadir=/data/MysqL
basedir=/usr/local/MysqL
socket=/usr/local/MysqL/MysqL.sock
port=3306
pid-file=/usr/local/MysqL/MysqL.pid
[client]
socket=/usr/local/MysqL/MysqL.sock

6、配置数据的启动文件

[root@centos7 ~]#cp  -a  /usr/local/MysqL/support-files/MysqL.server  /etc/init.d/MysqLd
[root@centos7 ~]#sed -Ei 's#^(basedir=)$#\1\/usr\/local\/MysqL#' /etc/init.d/MysqLd
[root@centos7 ~]#sed -Ei 's#^(datadir=)$#\1\/data\/MysqL#' /etc/init.d/MysqLd

8、PATH路径

[root@centos7 ~]#echo "PATH=/usr/local/MysqL/bin:$PATH" > /etc/profile.d/MysqL.sh
[root@centos7 ~]#. /etc/profile.d/MysqL.sh 

9、启动数据库并设置开机启动

[root@centos7 ~]#systemctl start MysqL
[root@centos7 ~]#chkconfig --add MysqLd

10、验证数据库是否编译成功

[root@centos7 ~]#ss -ntulp
Netid  State      Recv-Q Send-Q                         Local Address:Port                                        Peer Address:Port              
tcp    LISTEN     0      128                                        *:22                                                     *:*                   users:(("sshd",pid=1369,fd=3))
tcp    LISTEN     0      100                                127.0.0.1:25                                                     *:*                   users:(("master",pid=2270,fd=13))
tcp    LISTEN     0      80                                        :::3306                                                  :::*                   users:(("MysqLd",pid=1667,fd=19))


[root@centos7 ~]#MysqL
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 10
Server version: 10.2.31-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)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| MysqL              |
| performance_schema |
| test               |
+--------------------+
4 rows in set (0.00 sec)

错误分析:

1、MySQL命令找不到

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-q2AlZHoA-1638186802628)(C:\Users\HP\AppData\Roaming\Typora\typora-user-images\1638185907305.png)]

###通常是PATH路径问题
echo "PATH=/usr/local/MysqL/bin:$PATH" > /etc/profile.d/MysqL.sh/

2、如下问题

在这里插入图片描述

###在配置文件注释该行
[root@centos7 ~]#cat /etc/my.cnf |grep -n "symbolic-links=0"
10:symbolic-links=0

3、缺少相关包

在这里插入图片描述

[root@centos7 ~]#yum install libncurses* -y

4、权限问题

[ERROR] Can't start server : Bind on unix socket: Permission denied
[ERROR] Do you already have another MysqLd server running on socket: 
[ERROR] /usr/local/MysqL/MysqL.sock ?
Aborting
[ERROR] Can't start server : Bind on unix socket: Permission denied
[ERROR] Do you already have another MysqLd server running on socket: /usr/local/MysqL/MysqL.sock ?
[ERROR] Aborting
MysqLd_safe MysqLd from pid file /usr/local/MysqL/MysqL.pid ended

[root@centos7 ~]#chown -R MysqL.MysqL /usr/local/mariadb* /usr/local/MysqL*

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐