Centos8 二进制安装MariaDB-10.2.31

2021/11/30 7:06:29

本文主要是介绍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*


这篇关于Centos8 二进制安装MariaDB-10.2.31的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程