一般我不太愿意用mysql,那个玩意,有的时候不太友好。
我还是比较喜欢mariadb。
安装MariaDB之前,首先要安装cmake,另外为了保证不缺依赖,使用yum或者rpm安装依赖:readline-devel,zlib-devel,openssl-devel,libaio-devel并且readline-devel依赖于ncurses-devel,如果使用yum的话会自动将所需依赖安装好,具体命令如下:
yum -y install zlib-devel
yum -y install openssl-devel
yum -y install libaio-devel
yum -y install ncurses-devel
https:
//cmake.org/files/v3.12/cmake-3.12.0-rc1.tar.gz
(cmake.org/files/v3.12…)
-3.12.0
-rc1.tar.gz
-3.12.0
-rc1
这个安装和php及nginx的安装类似,只是mariadb的编译是使用cmake
这里提前预定mysql的安装目录为/usr/local/mariadb并且数据表文件目录为/usr/local/mariadb /mysqldata,
wget https://downloads.mariadb.org/f/mariadb-10.5.6/source/mariadb-10.5.6.tar.gz
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
初始化成功:
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/
至此,mariadb安装成功,现在,我们来启动数据库:
启动成功:
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命令:
比较长,用着不太方便,简化方式其实和php是一样的:
添加内容:
修改完成,重载一下文件:
或者创建软连接
Mariadb默认没有密码,所以直接使用
如下所示:
[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》
原因是找不到本地套接字文件mysql.sock
默认位置是在/tmp/mysql.sock,但是我这里在my.cnf中配置了其位置:
在/usr/local/mariadb/tmp/mysql.sock
查看当前目录下是否有该文件,没有的话,重新启动mariadb,会自动生成mysql.sock文件,不要自己手动创建。
使用如下命令:(该命令,是我在安装时已配置好)
确保rc.local 文件有执行权限,否则,开机启动不生效
添加如下内容:
至此,centos编译安装mariadb完成。
我这里都是指定位置安装,配置文件都在安装目录下,因此删除的时候相对比较方便。
升级的情况,之后要升级的时候会在写。
卸载软件的话,直接删除目录就好。
到此这篇关于centos编译安装mariadb的文章就介绍到这了,更多相关centos编译安装mariadb内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!