前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >MariaDB的二进制格式安装

MariaDB的二进制格式安装

作者头像
用户1456517
发布2019-03-05 16:12:13
6880
发布2019-03-05 16:12:13
举报
文章被收录于专栏:芝麻实验室芝麻实验室

关于MariaDB

MariaDBMySQL的一个分支,由MySQL的创始人Michael Widenius主导开发,当期主要由开源社区在维护,采用GPL授权许可。MariaDB的目的是完全兼容MySQL,包括API和命令行,使之能轻松成为MySQL的代替品。MariaDB以源码二进制rpm/deb格式分发。

安装前工作

1.安装开发者工具

代码语言:javascript
复制
[root@centos7 ~]# yum -y groupinstall "development tools"

2.创建mysql用户

代码语言:javascript
复制
[root@centos7 ~]# useradd -r -u 55 -m -d /data -s /sbin/nologin mysql  #注意,应创建为系统用户
[root@centos7 ~]# id mysql
uid=55(mysql) gid=55(mysql) groups=55(mysql)

3.获取二进制程序

代码语言:javascript
复制
[root@centos7 ~]# wget http://mirrors.tuna.tsinghua.edu.cn/mariadb//mariadb-10.2.8/bintar-linux-x86_64/mariadb-10.2.8-linux-x86_64.tar.gz
[root@centos7 ~]# tar zxvf mariadb-10.2.8-linux-x86_64.tar.gz -C /usr/local/
[root@centos7 ~]# cd /usr/local/
[root@centos7 local]# ls
bin  games    lib    libexec                      sbin   src
etc  include  lib64  mariadb-10.2.8-linux-x86_64  share
[root@centos7 local]# mv mariadb-10.2.8-linux-x86_64/ mysql  #必须重命名为mysql或创建名为mysql的软链接 因为该路径在二进制文件中已定义 不可直接修改
[root@centos7 local]# ls
bin  etc  games  include  lib  lib64  libexec  mysql  sbin  share  src

准备相关文件

1.准备配置文件

代码语言:javascript
复制
[root@centos7 local]# cd mysql/
[root@centos7 mysql]# mkdir /etc/mysql
[root@centos7 mysql]# cp support-files/my-small.cnf /etc/mysql/my.cnf  #拷贝官方配置文件,本例中拷贝的为较小数据量的场景配置文件
[root@centos7 mysql]# vim /etc/mysql/my.cnf
[mysqld]
port            = 3306
socket          = /tmp/mysql.sock
datadir = /data  #添加该行。该参数用于指定数据库的磁盘存储路径

2.创建日志文件

代码语言:javascript
复制
[root@centos7 mysql]# cat /etc/my.cnf |grep log
log-error=/var/log/mariadb/mariadb.log 
[root@centos7 mysql]# mkdir /var/log/mariadb
[root@centos7 mysql]# touch /var/log/mariadb/mariadb.log
[root@centos7 mysql]# chown -R mysql:mysql /var/log/mariadb/  #至少要保证mysql用户有读写日志的权限
[root@centos7 mysql]# ll /var/log/mariadb/
total 0
-rw-r--r-- 1 mysql mysql 0 Sep 25 09:12 mariadb.log
[root@centos7 mysql]# ll /var/log/mariadb/ -d
drwxr-xr-x 2 mysql mysql 4096 Sep 25 09:12 /var/log/mariadb/

安装数据库

1.初始化mariadb数据库

代码语言:javascript
复制
[root@centos7 mysql]# ./scripts/mysql_install_db --datadir=/data --user=mysq
l  #--datadir=数据库磁盘存储目录, --user=以指定用户身份运行,建议使用mysql用户
Installing MariaDB/MySQL system tables in '/data' ...
OK  #看到这个字样 意味着初始化成功。需要注意的是,如果没有事先创建日志文件并赋权,此处可能会有warnning警报

To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system  #要启动mysqld需要拷贝服务脚本

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 centos7 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'

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@centos7 mysql]# ls /data
aria_log.00000001  ibdata1      multi-master.info  mysql-bin.000003
aria_log_control   ib_logfile0  mysql              mysql-bin.index
centos7.pid        ib_logfile1  mysql-bin.000001   performance_schema
ib_buffer_pool     ibtmp1       mysql-bin.000002

2.准备服务脚本

代码语言:javascript
复制
[root@centos7 mysql]# cp support-files/mysql.server /etc/init.d/mysqld  #拷贝服务脚本到init.d
[root@centos7 mysql]# chkconfig --add mysqld  #添加开机自启服务
[root@centos7 mysql]# chkconfig mysqld --list

Note: This output shows SysV services only and does not include native
      systemd services. SysV configuration data might be overridden by nativ
e
      systemd configuration.

      If you want to list systemd services use 'systemctl list-unit-files'.
      To see services enabled on particular target use
      'systemctl list-dependencies [target]'.

mysqld          0:off   1:off   2:on    3:on    4:on    5:on    6:off

3.添加服务至PATH

代码语言:javascript
复制
[root@centos7 bin]# cd bin
[root@centos7 bin]# mysql  #此时会提示命令不存在
-bash: mysql: command not found
[root@centos7 bin]# vim /etc/profile.d/mysqld.sh
export PATH=/usr/local/mysql/bin:$PATH
[root@centos7 bin]# . /etc/profile.d/mysqld.sh  #重新读取PATH值 使其修改生效;此时,我们可以便可以通过二进制安装包自带的帮助手册`mysql --help`或`man mysql`来获取更多帮助。

4.启动mariadb

代码语言:javascript
复制
[root@centos7 bin]# service mysqld start
Starting mysqld (via systemctl):                           [  OK  ]
[root@centos7 bin]# ss -tnl  #查看3306端口是否已处于监听状态
State      Recv-Q Send-Q Local Address:Port               Peer Address:Port

LISTEN     0      128        *:111                    *:*
LISTEN     0      128        *:22                     *:*
LISTEN     0      100    127.0.0.1:25                     *:*

LISTEN     0      80        :::3306                  :::*
LISTEN     0      128       :::111                   :::*
LISTEN     0      128       :::22                    :::*
LISTEN     0      100      ::1:25                    :::*

安装后工作

1.运行安全脚本

代码语言:javascript
复制
[root@centos7 bin]# ./mysql_secure_installation

2.连接数据库

代码语言:javascript
复制
[root@centos7 bin]# mysql -uroot -p
MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
+--------------------+
3 rows in set (0.00 sec)

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2017/09/25,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
云数据库 SQL Server
腾讯云数据库 SQL Server (TencentDB for SQL Server)是业界最常用的商用数据库之一,对基于 Windows 架构的应用程序具有完美的支持。TencentDB for SQL Server 拥有微软正版授权,可持续为用户提供最新的功能,避免未授权使用软件的风险。具有即开即用、稳定可靠、安全运行、弹性扩缩等特点。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档