Linux CentOS编译安装MariaDB

原文地址: https://segmentfault.com/a/1190000009909776
整理自用.

删除CentOS默认数据库配置文件

  • 查看默认数据库配置文件
1
2
3
4
5
6
[root@caoxl ~]# find -H /etc/ | grep my.c
/etc/pki/tls/certs/make-dummy-cert
/etc/pki/tls/certs/renew-dummy-cert
/etc/my.cnf.d
/etc/my.cnf.d/mysql-clients.cnf
/etc/my.cnf
  • 删除默认数据库配置文件
1
[root@caoxl ~]# rm -rf /etc/my.cnf /etc/my.cnf.d/
  • 再次查看默认数据库配置文件
1
2
3
[root@caoxl ~]# find -H /etc/ | grep my.c
/etc/pki/tls/certs/make-dummy-cert
/etc/pki/tls/certs/renew-dummy-cert

到目前为止, 系统最小化安装自带的数据库配置文件已经删除干净了!

卸载系统自带mariadb-libs

  • 查询
1
2
[root@caoxl ~]# rpm -qa|grep mariadb-libs
mariadb-libs-5.5.52-1.el7.x86_64
  • 卸载
1
[root@caoxl ~]# rpm -e mariadb-libs-5.5.52-1.el7.x86_64 --nodeps

安装相关包

1
2
3
[root@caoxl ~]# yum -y install libaio libaio-devel bison bison-devel zlib-devel openssl openssl-devel ncurses
ncurses-devel libcurl-devel libarchive-devel boost boost-devel lsof wget gcc gcc-c++ make cmake perl
kernel-headers kernel-devel pcre-devel

MariaDB官网复制源码包链接地址并下载解压

1
2
3
4
5
6
7
[root@caoxl ~]# mkdir /download

[root@caoxl ~]# cd /download

[root@caoxl download]# wget https://downloads.mariadb.org/interstitial/mariadb-10.2.6/source/mariadb-10.2.6.tar.gz

[root@caoxl download]# tar -zxvf mariadb-10.2.6.tar.gz

创建MariaDB安装目录、数据库存放目录、建立用户和目录

这里提前预定MariaDB的安装目录为/usr/local/mysql并且数据库目录为/data/mysql,
这里要建立系统用户及组和数据库存放目录,并且将数据库存放目录赋予mysql用户及组权限,操作如下:
请注意特别说明一下:这里说的数据库目录是指的具体数据库存储文件, 而不是安装文件!

  • 创建mysql系统用户组
1
groupadd -r mysql
  • 创建系统用户mysql并加入到mysql系统用户组
1
useradd -r -g mysql -s /sbin/nologin -d /usr/local/mysql -M mysql
  • 创建mariadb安装目录
1
mkdir -p /usr/local/mysql
  • 创建数据库存放目录
1
mkdir -p /data/mysql
  • 改变数据库存放目录所属用户及组为 mysql:mysql
1
chown -R mysql:mysql /data/mysql

执行编译安装

1
2
3
4
5
6
7
8
9
10
11
12
13
14
cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/data/mysql \
-DSYSCONFDIR=/etc \
-DWITHOUT_TOKUDB=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STPRAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWIYH_READLINE=1 \
-DWIYH_SSL=system \
-DVITH_ZLIB=system \
-DWITH_LOBWRAP=0 \
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci

配置MariaDB

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
cd /usr/local/mysql/
scripts/mysql_install_db --user=mysql --datadir=/data/mysql

> 输出以下信息:
Installing MariaDB/MySQL system tables in '/data/mysql' ...
OK

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

PLEASE REMEMBER TO SET A PASSWORD FOR THE MariaDB root USER !
To do so, start the server, then issue the following commands:

'./bin/mysqladmin' -u root password 'new-password'
'./bin/mysqladmin' -u root -h localhost.localdomain password 'new-password'

Alternatively you can run:
'./bin/mysql_secure_installation'

which will also give you the option of removing the test
databases and anonymous user created by default. This is
strongly recommended for production servers.

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

You can start the MariaDB daemon with:
cd '.' ; ./bin/mysqld_safe --datadir='/data/maria'

You can test the MariaDB daemon with mysql-test-run.pl
cd './mysql-test' ; perl mysql-test-run.pl

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

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

复制MariaDB配置文件到/etc目录

1
2
cd /usr/local/mysql/
cp support-files/my-large.cnf /etc/my.cnf

创建启动脚本

1
cp support-files/mysql.server /etc/rc.d/init.d/mysqld

启动mysqld服务

1
cp support-files/mysql.server /etc/rc.d/init.d/mysqld

启动mysqld服务

1
/etc/rc.d/init.d/mysqld start
1
2
3
4
5
6
7
8
[root@caoxl www]# service mysqld status
MariaDB is not running [FAILED]
[root@caoxl www]# service mysqld start
Starting MariaDB.181115 14:26:03 mysqld_safe Logging to '/data/mysql/caoxl.err'.
181115 14:26:03 mysqld_safe Starting mysqld daemon with databases from /data/mysql
[ OK ]
[root@caoxl www]# service mysqld status
MariaDB running (31114) [ OK ]

配置环境变量, 以便在任何目录下输入mysql

1
2
3
4
5
6
7
8
9
10
vim /etc/profile.d/mysql.sh

# 输入以下内容
export PATH=$PATH:/usr/local/mysql/bin/

# 为脚本赋于可执行权限
chmod 0777 /etc/profile.d/mysql.sh

# 进行mysql.sh脚本所在目录, 并执行脚本, 以立即生效环境变量
source /etc/profile.d/mysql.sh

初始化MariaDB

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
./bin/mysql_secure_installation

> 以下提示:

Enter current password for root (enter for none): 输入当前root密码(没有输入)

Set root password? [Y/n] 设置root密码?(是/否)

New password: 输入新root密码

Re-enter new password: 确认输入root密码

Password updated successfully! 密码更新成功

By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.

默认情况下,MariaDB安装有一个匿名用户,
允许任何人登录MariaDB而他们无需创建用户帐户。
这个目的是只用于测试,安装去更平缓一些。
你应该进入前删除它们生产环境。

Remove anonymous users? [Y/n] 删除匿名用户?(是/否)

Normally, root should only be allowed to connect from 'localhost'. This
ensures that someone cannot guess at the root password from the network.

通常情况下,root只应允许从localhost连接。
这确保其他用户无法从网络猜测root密码。

Disallow root login remotely? [Y/n] 不允许root登录远程?(是/否)

By default, MariaDB comes with a database named 'test' that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.

默认情况下,MariaDB提供了一个名为“测试”的数据库,任何人都可以访问。
这也只用于测试,在进入生产环境之前应该被删除。

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

重新加载权限表将确保所有到目前为止所做的更改将立即生效。

Reload privilege tables now? [Y/n] 现在重新加载权限表(是/否)

All done! If you've completed all of the above steps, your MariaDB
installation should now be secure.

全部完成!如果你已经完成了以上步骤,MariaDB安装现在应该安全。

Thanks for using MariaDB!

感谢使用MariaDB!

进入MariaDB终端

1
mysql -u username -p password

参考

Powered by Hexo and Hexo-theme-hiker

Copyright © 2017 - 2023 Keep It Simple And Stupid All Rights Reserved.

访客数 : | 访问量 :