基于CentOS6.9的MariaDB二进制安装

去mariadb官网下载二进制安装包

进入官网www.mariadb.org选择 Download

进入官网www.mariadb.org选择 Download

点击 Download

选择版本

这里选择5.5.57版本

*选择需要安装的二进制安装包

选择基于 x86平台使用与Linux的编译完的二进制包

谢谢MariaDB的免费软件,开源精神是世界的...

最后这里是填写相关信息的,这里我们无需填写直接选择下载


安装环境

Linux 操作系统 CentOS 6.9 版本

创建数据库存放路径和权限设置

创建存放数据库目录 -->创建系统用户账号 -->设置系统用户对/app/data目录的权限

[root@host-b app]#pwd
/app
[root@host-b app]#
[root@host-b app]#mkdir /app/data
[root@host-b app]#
[root@host-b app]#rz

[root@host-b app]#getent passwd mysql
[root@host-b app]#
[root@host-b app]#ls
data  mariadb-5.5.57-linux-x86_64.tar.gz
[root@host-b app]#
[root@host-b app]#useradd -r -d /app/data -s /sbin/nologin -u 36 mysql
[root@host-b app]#id mysql
uid=36(mysql) gid=36(mysql) groups=36(mysql)
[root@host-b app]#ll
total 218916
drwxr-xr-x. 2 root root      4096 Aug  2 12:33 data
-rw-r--r--. 1 root root 224162771 Aug  2  2017 mariadb-5.5.57-linux-x86_64.tar.gz
[root@host-b app]#
[root@host-b app]#chown mysql:mysql /app/data
[root@host-b app]#ll -d data
drwxr-xr-x. 2 mysql mysql 4096 Aug  2 12:33 data
[root@host-b app]#

解压缩包

我们安装的是人家已经编译好了的二进制程序包,所以解压后路径不能随便放,按人家编译好的环境来解压!路径为/usr/local

特别注意路径要指定

[root@host-b app]#tar xvf mariadb-5.5.57-linux-x86_64.tar.gz -C /usr/local/  <--路径一定要正确

修改二进制程序的名字和相关权限

因为我们安装的是人家已经编译好的二进制程序包,人家编译时规定名字叫mysql,所以我们要修改名字,或者创建软连接

修改解压后目录的名字 --> 创建软链接

修改mysql目录下的所有文件的所属组为mysql

为了有权限执行mysql目录下的程序,修改mysql目录下所有文件的所属组为mysql

到这之后,我们的二进制程序已经解压完了,虽然二进制程序有啦,但是还不能启动。如果现在就启动会报错的,比如路径错误等,所以接下来我们还需要修改配置文件

修改配置文件

1. 我们先打开看一下系统自带的配置文件

数据库路径与我们指定的/app/data不符合

2. 利用模板自己创建配置文件
选择配置文件模板
切进存放模板的目录选择模板

创建一个配置文件目录,把模板复制过去改名为 my.cfg

vim 编辑配给文件,数据库路径是必须配置

生成对应的mysql数据库并放在 /app/data 目录下

我们用一个脚本生成数据库即可,脚本在解压缩目录下的scripts目录里 :
/mysql_install_db

把 /mysql_install_db 脚本找出来

执行脚本 /mysql_install_db 生成数据库

[root@host-b mysql]#pwd
/usr/local/mysql      <---执行脚本的目录
[root@host-b mysql]#scripts/mysql_install_db --datadir=/app/data --user=mysql  <--指定路径和用户
Installing MariaDB/MySQL system tables in '/app/data' ...
170804  4:14:58 [Warning] 'THREAD_CONCURRENCY' is deprecated and will be removed in a fu
ture release.170804  4:14:58 [Note] ./bin/mysqld (mysqld 5.5.57-MariaDB) starting as process 4955 ...
OK
Filling help tables...
170804  4:14:59 [Warning] 'THREAD_CONCURRENCY' is deprecated and will be removed in a fu
ture release.170804  4:14:59 [Note] ./bin/mysqld (mysqld 5.5.57-MariaDB) starting as process 4963 ...
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 host-b.6.9 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='/app/data'

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/

[root@host-b mysql]#
[root@host-b mysql]#ll /app/data    <--查看该目录
total 1084
-rw-rw----. 1 mysql mysql   16384 Aug  4 04:14 aria_log.00000001
-rw-rw----. 1 mysql mysql      52 Aug  4 04:14 aria_log_control
drwx------. 2 mysql root     4096 Aug  4 04:14 mysql               <--mysql数据库
-rw-rw----. 1 mysql mysql   30346 Aug  4 04:14 mysql-bin.000001
-rw-rw----. 1 mysql mysql 1038814 Aug  4 04:14 mysql-bin.000002
-rw-rw----. 1 mysql mysql      38 Aug  4 04:14 mysql-bin.index
drwx------. 2 mysql mysql    4096 Aug  4 04:14 performance_schema
drwx------. 2 mysql root     4096 Aug  4 04:14 test
[root@host-b mysql]#
[root@host-b mysql]#

执行完 /mysql_install_db 脚本后 /app/data 目录下生成的数据库文件

把服务脚本准备好,设置相关权限启动服务

(1)把服务脚本 mysql.server 放到 /etc/inint.d/ 目录下,并修改为 mysqld
(2)设置为开机启动
(3)创建日志文件 mkdir /var/log/mysql.d 注意路径
(4)修改日志文件的所属主为 mysql
(5)service mysqld start 启动服务

把二进制程序路径添加到$PATH变量里

测试并设置口令

目前我们虽然能够登陆数据库但是不安全,因为没有设置安全口令谁都可以登录;这样不安全。

测试查看端都是否打开:

没有设置安全口令之前:

执行安全脚本mysql_secure_installation设置口令:


执行安全脚本mysql_secure_installation的代码块:

[root@host-b bin]#mysql_secure_installation 
/usr/local/mysql/bin/mysql_secure_installation: line 393: find_mysql_client: command not
 found
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):      <-- 输入当前root密码,这里是回车
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      <-- 设置root密码么? < 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          <-- 是否删除匿名用户? < 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] n   <-- 是否禁止root远程登录?   < n > 
 ... skipping.

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] n    <-- 是否删除测试数据库? < y/n都可以 >
 ... skipping.

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

Reload privilege tables now? [Y/n] y              <-- 现在从新加载权限表么? < 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!
[root@host-b bin]#

设置安全口令之后:


结语

到这里就完成整个MariaDB数据库的二进制安装!自己学习用的,如果能够帮到读者是我的荣幸;
最后还要感谢MariaDB数据库的开发者们免费提供的软件,开源精神是世界的!

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 159,458评论 4 363
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 67,454评论 1 294
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 109,171评论 0 243
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 44,062评论 0 207
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 52,440评论 3 287
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 40,661评论 1 219
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 31,906评论 2 313
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 30,609评论 0 200
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 34,379评论 1 246
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 30,600评论 2 246
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 32,085评论 1 261
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 28,409评论 2 254
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 33,072评论 3 237
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 26,088评论 0 8
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 26,860评论 0 195
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 35,704评论 2 276
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 35,608评论 2 270

推荐阅读更多精彩内容