centos源码搭建mariadb-10.3.13数据库

MariaDB Server是世界上最受欢迎的数据库服务器之一。它由MySQL的原始开发人员制作,并保证保持开源。

 

删除centos自带的mysql配置文件。

利用find查找my.c文件的位置

$ sudo find -H /etc/ |grep my.c

/etc/pki/tls/certs/make-dummy-cert
/etc/pki/tls/certs/renew-dummy-cert
/etc/my.cnf
/etc/my.cnf.d
/etc/my.cnf.d/mysql-clients.cnf

移动默认的mysql配置文件到其他目录。

$ sudo mv /etc/my.cnf* /opt/

检查

$ sudo find -H /etc/ |grep my.c
/etc/pki/tls/certs/make-dummy-cert
/etc/pki/tls/certs/renew-dummy-cert
 

卸载系统自带的mariadb

$ rpm -qa | grep mariadb
mariadb-libs-5.5.60-1.el7_5.x86_64
$ sudo yum -y remove mariadb-libs

安装依赖软件

$ sudo yum -y install libaio libaio-devel bison bison-devel zlib-devel openssl openssl-devel ncurses ncurses-devel libcurl-devellibarchive-devel boost boost-devel lsof wget gcc gcc-c++ make cmake perlkernel-headers kernel-devel pcre-devel
 

创建源码安装包下载目录

创建下载目录

$ mkdir  -p /data/package

下载mariadb数据库

$ cd /data/package/

$ wget http://mirror.rise.ph/mariadb//mariadb-10.3.13/source/mariadb-10.3.13.tar.gz

建立软件安装位置

$ mkdir /data/soft/

 

解压源码包

$ tar -xf mariadb-10.3.13.tar.gz -C /data/soft/

 

让root用户创建一个mysql用户

$ su

# groupadd -r mysql

# useradd -r -g mysql -s /sbin/nologin -d /data/soft/mysql -M mysql

以下是上面创建系统用户mysql的各个参数说明:

-r: 添加系统用户( 这里指将要被创建的系统用户mysql )

-g: 指定要创建的用户所属组( 这里指添加到新系统用户mysql到mysql系统用户组 )

-s: 新系统帐户的登录shell( /sbin/nologin 这里设置为将要被创建系统用户mysql不能用来登录系统 )

-d: 新帐户的主目录( 这里指定将要被创建的系统用户mysql的家目录为 /usr/local/mysql )

-M: 不要创建用户的主目录( 也就是说将要被创建的系统用户mysql不会在 /home 目录下创建 mysql 家目录 )

# exit

 

创建数据库程序目录并授权给mysql

$ sudo mkdir /data/soft/mysql

$ sudo setfacl -m u:mysql:rwx -R /data/soft/mysql/

 

进入到源码目录开始编译安装

$ cd /data/soft/mariadb-10.3.13/

$ ls
appveyor.yml  CMakeLists.txt      CREDITS            extra               libmariadb   mysys      README.md   storage        VERSION
BUILD         config.h.cmake      dbug               include             libmysqld    mysys_ssl  scripts     strings        vio
BUILD-CMAKE   configure.cmake     debian             INSTALL-SOURCE      libservices  pcre       sql         support-files  win
client        COPYING             Docs               INSTALL-WIN-SOURCE  man          plugin     sql-bench   tests          wsrep
cmake         COPYING.thirdparty  EXCEPTIONS-CLIENT  KNOWN_BUGS.txt      mysql-test   randgen    sql-common  unittest       zlib

$ cmake -DCMAKE_INSTALL_PREFIX=/data/soft/mysql-DMYSQL_DATADIR=/mariadb -DSYSCONFDIR=/data/soft/mysql -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=/var/lib/mysql/mysql.sock -DMYSQL_TCP_PORT=3306 -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci

如果编译失败请删除CMakeCache.txt文件重新编译

编译安装

$ make -j 4 && make install

 

配置MariaDB

$ cd /data/soft/mysql/ && ls
bin      COPYING.thirdparty  data               include         lib  mysql-test  README-wsrep  share      support-files
COPYING  CREDITS             EXCEPTIONS-CLIENT  INSTALL-BINARY  man  README.md   scripts       sql-bench

创建数据库目录并授权

$ sudo mkdir /mariadb

$ sudo setfacl -m u:mysql:rwx /mariadb/

生成数据库

$ sudo ./scripts/mysql_install_db --user=mysql --datadir=/mariadb
Installing MariaDB/MySQL system tables in '/mariadb' ...
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 git 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='/mariadb'

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/

 

拷贝配置文件到指定目录

$ cp support-files/wsrep.cnf my.cnf

编辑配置文件

$ vim my.cnf

[client]
port = 3306
socket = /var/lib/mysql/mysql.sock

[mysqld_safe]
log-error = /log/mariadb/mariadb_error.log
pid-file = /var/run/mariadb/mariadb.pid

[mysqld]
port = 3306
socket = /var/lib/mysql/mysql.sock
basedir = /data/soft/mysql
datadir = /mariadb
pid-file = /var/run/mariadb/mariadb.pid

创建错误日志文件目录

$ mkdir /log/mariadb

 

生成mysql启动文件

$ sudo cp support-files/mysql.server /etc/init.d/mariadb

制定my.cnf文件位置

$ sudo vim /etc/init.d/mariadb

  conf=/data/soft/mysql/my.cnf

 

启动数据库

$ sudo /etc/init.d/mariadb start

$ ps -ef|grep mysql
root      42531      1  0 14:24 ?        00:00:00 /bin/sh /data/soft/mysql/bin/mysqld_safe --datadir=/mariadb --pid-file=/mariadb/git.pid
mysql     42736  42531  0 14:24 ?        00:00:00 /data/soft/mysql/bin/mysqld --basedir=/data/soft/mysql --datadir=/mariadb --plugin-dir=/data/soft/mysql/lib/plugin --user=mysql --wsrep_on=1 --wsrep_provider=none --log-error=/log/mariadb/mariadb_error.log --pid-file=/mariadb/git.pid --socket=/var/lib/mysql/mysql.sock --port=3306
www       43179   7137  0 14:39 pts/0    00:00:00 grep --color=auto mysql

$ sudo ./bin/mysql

MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
+--------------------+
4 rows in set (0.000 sec)

MariaDB [(none)]> \q
Bye

 

初始化数据库,配置密码等

$ sudo ./bin/mysql_secure_installation

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none):
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n] y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
 ... Success!


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.

Remove anonymous users? [Y/n] y
 ... Success!

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

Disallow root login remotely? [Y/n] y
 ... Success!

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.

Remove test database and access to it? [Y/n] y
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

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

Reload privilege tables now? [Y/n] y
 ... Success!

Cleaning up...

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

Thanks for using MariaDB!

大致意思如下

注意:建议所有MariaDB运行此脚本的所有部分
服务器在生产中使用!请仔细阅读每一步!
为了登录MariaDB来保护它,我们需要电流
根用户的密码。如果你刚刚安装了MariaDB
您还没有设置根密码,密码将为空,
删除匿名用户?[Y / n] Y
新密码:
重新输入新密码:
密码更新成功!
重新加载权限表. .
…成功!
默认情况下,MariaDB安装有一个匿名用户,允许任何人使用
无需为其创建用户帐户即可登录MariaDB
他们。这仅用于测试和安装
再顺一点。你应该在搬进a之前把它们搬走
生产环境。
删除匿名用户?[Y / n] Y
…成功!
正常情况下,root只能从“localhost”连接。这
确保无法从网络猜测根密码。
不允许远程root登录?[Y / n] Y
…成功!
默认情况下,MariaDB附带一个名为“test”的数据库,任何人都可以使用
访问。这也仅用于测试,应该删除
在进入生产环境之前。
删除测试数据库并访问它?[Y / n] Y
-删除测试数据库…
…成功!
-删除测试数据库上的特权…
…成功!
重新加载特权表将确保到目前为止所做的所有更改
将立即生效。
现在重新加载权限表?[Y / n] Y
…成功!
清理…
全部完成!如果你已经完成了以上所有步骤,你的MariaDB
安装现在应该是安全的。
感谢使用MariaDB!

检查

$ ./bin/mysql -uroot -p
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 22
Server version: 10.3.13-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)]> select host,user,password from mysql.user;
+-----------+------+-------------------------------------------+
| host      | user | password                                  |
+-----------+------+-------------------------------------------+
| localhost | root | *D604EC8929C0B95B5D57468F8D3E81D1014F1CCA |
| 127.0.0.1 | root | *D604EC8929C0B95B5D57468F8D3E81D1014F1CCA |
| ::1       | root | *D604EC8929C0B95B5D57468F8D3E81D1014F1CCA |
+-----------+------+-------------------------------------------+
3 rows in set (0.000 sec)

$ sudo vim /etc/profile

 

配置环境变量

# mysql
export MYSQL_HOME=/data/soft/mysql
export PATH=$PATH:$MYSQL_HOME/bin

$ source /etc/profile

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值