centos编译安装mariadb的详细过程(centos7yum安装mariadb)干货满满

随心笔谈12个月前发布 admin
93 0



目录centos编译安装mariadb1:安装cmake环境(1):进入/usr/local/download/目录(2):解压源码包(3):解压CMake源码包(4):进入cmark的源码目录(5):运行当前目录下的一个文件(6):编译并安装(时间稍长)(7):查看版本号2:安装mariadb(1):下载(2):创建用户及用户组(3):解压、预编译、编译安装(4):配置启动文件及权限等(5):数据初始化(7):确保/usr/local/mariadb目录下的所有文件权限都是mysql(8):启动mysql(9):简化mariadb操作命令(10):链接mariadb(11):重启服务器,运行mariadb报错:(12):设置开机启动

一般我不太愿意用mysql,那个玩意,有的时候不太友好。

我还是比较喜欢mariadb。

安装MariaDB之前,首先要安装cmake,另外为了保证不缺依赖,使用yum或者rpm安装依赖:readline-devel,zlib-devel,openssl-devel,libaio-devel并且readline-devel依赖于ncurses-devel,如果使用yum的话会自动将所需依赖安装好,具体命令如下:

yum -y install readline-devel
yum -y install zlib-devel
yum -y install openssl-devel
yum -y install libaio-devel
yum -y install ncurses-devel
cd /usr/local/download
wget
https:
//cmake.org/files/v3.12/cmake-3.12.0-rc1.tar.gz

(cmake.org/files/v3.12…)

tar -zxvf cmake
-3.12.0
-rc1.tar.gz
cd cmake
-3.12.0
-rc1
https://www.jb51.net/article/bootstrap
gmake&&gmake install
cmake –version

这个安装和php及nginx的安装类似,只是mariadb的编译是使用cmake

这里提前预定mysql的安装目录为/usr/local/mariadb并且数据表文件目录为/usr/local/mariadb /mysqldata,

cd /usr/local/download
wget https://downloads.mariadb.org/f/mariadb-10.5.6/source/mariadb-10.5.6.tar.gz
groupadd mysql
useradd -s /sbin/nologin -r -g mysql mysql
# 解压
tar -zxvf mariadb-10.5.6.tar.gz
# 进入目录
cd mariadb-10.5.6
# 预编译,将与
cmake -j . \
-DCMAKE_INSTALL_PREFIX=/usr/local/mariadb \
-DMYSQL_DATADIR=/usr/local/mariadb/mysqldata/ \
-DSYSCONFDIR=/usr/local/mariadb \
-DMYSQL_USER=mysql \
-DMYSQL_TCP_PORT=3306 \
-DWITHOUT_TOKUDB=1 \
-DMYSQL_UNIX_ADDR=/usr/local/mariadb/tmp/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci

# 编译安装
make&&make install

# 进入安装目录
cd /usr/local/mariadb/
# 创建启动文件
cp support-files/mysql.server /etc/init.d/mysqld
# 添加执行权限
chmod +x /etc/init.d/mysqld
# 创建存放数据表目录
mkdir -p mkdir /usr/local/mariadb/mysqldata/
# 创建存放mysql.sock目录
mkdir -p mkdir /usr/local/mariadb/tmp/
# 修改mariadb目录权限
chown -R mysql:mysql /usr/local/mariadb/
# 创建mariadb配置文件
vim /usr/local/mariadb/my.cnf
[mysqld]
basedir=/usr/local/mariadb/
datadir=/usr/local/mariadb/mysqldata/
port=3306
pid-file=/usr/local/mariadb/mysqldata/mysql.pid
socket=/usr/local/mariadb/tmp/mysql.sock

[mysqld_safe]
log-error=/usr/local/mariadb/mysqldata/mysql.log

[client]
port=3306
socket=/usr/local/mariadb/tmp/mysql.sock
default-character-set=utf8

# 删除默认mariadb配置文件(默认加载默认的my.cnf文件,不删除,启动会报错)
rm -rf /etc/my.cnf

/usr/local/mariadb/scripts/mysql_install_db –datadir=/usr/local/mariadb/mysqldata

初始化成功:

[root@iZuf60ynur81p6k0ysvtneZ mariadb]# /usr/local/mariadb/scripts/mysql_install_db –datadir=/usr/local/mariadb/mysqldata
Installing MariaDB/MySQL system tables in ‘/usr/local/mariadb/mysqldata’ …
OK

To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system

Two all-privilege accounts were created.
One is root@localhost, it has no password, but you need to
be system ‘root’ user to connect. Use, for example, sudo mysql
The second is root@localhost, it has no password either, but
you need to be the system ‘root’ user to connect.
After connecting you can set the password, if you would need to be
able to connect as any of these users with a password and without sudo

See the MariaDB Knowledgebase at https://mariadb.com/kb or the
MySQL manual for more instructions.

You can start the MariaDB daemon with:
cd ‘.’ ; https://www.jb51.net/article/bin/mysqld_safe –datadir=’/usr/local/mariadb/mysqldata’

You can test the MariaDB daemon with mysql-test-run.pl
cd ‘https://www.jb51.net/article/mysql-test’ ; perl mysql-test-run.pl

Please report any problems at https://mariadb.org/jira

The latest information about MariaDB is available at https://mariadb.org/.
You can find additional information about the MySQL part at:
https://dev.mysql.com
Consider joining MariaDB’s strong and vibrant community:
https://mariadb.org/get-involved/

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

至此,mariadb安装成功,现在,我们来启动数据库:

/etc/init.d/mysqld start

启动成功:

[root@iZuf60ynur81p6k0ysvtneZ mariadb]# /etc/init.d/mysqld start
Starting MariaDB.201015 17:26:58 mysqld_safe Logging to ‘/usr/local/mariadb/mysqldata/mysql.log’.
201015 17:26:58 mysqld_safe Starting mariadbd daemon with databases from /usr/local/mariadb/mysqldata
[ OK ]

默认操作mariadb命令:

/usr/local/mariadb/bin/mysql

比较长,用着不太方便,简化方式其实和php是一样的:

vim /root/.bash_profile

添加内容:

alias mysql=/usr/local/mariadb/bin/mariadb

修改完成,重载一下文件:

source /root/.bash_profile

或者创建软连接

ln -s /usr/local/mariadb/bin/mariadb /usr/bin/mariadb

Mariadb默认没有密码,所以直接使用

mysql -uroot -p
如下所示:
[root@iZuf60ynur81p6k0ysvtneZ mariadb]# mysql -uroot -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 6
Server version: 10.5.6-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)]>

数据库的其他配置,请移步《Centos7.6配置lnmp》

ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/usr/local/mariadb/tmp/mysql.sock’ (2)

原因是找不到本地套接字文件mysql.sock

默认位置是在/tmp/mysql.sock,但是我这里在my.cnf中配置了其位置:

在/usr/local/mariadb/tmp/mysql.sock

查看当前目录下是否有该文件,没有的话,重新启动mariadb,会自动生成mysql.sock文件,不要自己手动创建。

使用如下命令:(该命令,是我在安装时已配置好)

/etc/rc.d/init.d/mysqld restart

确保rc.local 文件有执行权限,否则,开机启动不生效

vim /etc/rc.d/rc.local

添加如下内容:

/etc/rc.d/init.d/mysqld restart

至此,centos编译安装mariadb完成。

我这里都是指定位置安装,配置文件都在安装目录下,因此删除的时候相对比较方便。

升级的情况,之后要升级的时候会在写。

卸载软件的话,直接删除目录就好。

到此这篇关于centos编译安装mariadb的文章就介绍到这了,更多相关centos编译安装mariadb内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!

您可能感兴趣的文章:CentOS6.7系统中编译安装MariaDB数据库CentOS 8 安装 MariaDB的详细教程centos 7下安装mysql(MariaDB)的教程CentOS 7中成功安装MariaDB的方法教程详解如何在 CentOS 7 上安装和安全配置 MariaDB 10CentOS 7.2 安装MariaDB详细过程CentOS安装和设置MariaDB的教程详解Centos 使用YUM安装MariaDB

© 版权声明

相关文章