Mysql与MariaDB

    Mysql是一个关系型数据库,由mysql ab公司开发,在2008年被sun公司收购,2009年被oracle公司收购。mysql最新版本是5.7GA/8.0DMR。mysql 5.6版本变化比较大,5.7版本性能上有很大提升。

    Mariadb是mysql的一个分支,最新版本是10.2版本。它是由Mysql原作者带领大部分原班人马创立的SkySQL公司维护。

    Mariadb5.5版本对应MySQL的5.5版本,10.0版本对应MySQL的5.6版本。

Tips:
Community 社区版本,Enterprise 企业版,
GA(Generally Available)指通用版本,在生产环境中用的,
DMR(Development Milestone Release)开发里程碑发布版,
RC(Release Candidate)发行候选版本,Beta开放测试版本,Alpha内部测试版本。


安装MariaDB

1、下载安装文件

[root@juispan src]# wget https://downloads.mariadb.com/MariaDB/mariadb-10.2.6/bintar-linux-glibc_214-x86_64/mariadb-10.2.6-linux-glibc_214-x86_64.tar.gz
--2017-07-21 07:01:06--  https://downloads.mariadb.com/MariaDB/mariadb-10.2.6/bi             ntar-linux-glibc_214-x86_64/mariadb-10.2.6-linux-glibc_214-x86_64.tar.gz
正在解析主机 downloads.mariadb.com (downloads.mariadb.com)... 51.255.94.155, 200             1:41d0:1004:249b::
正在连接 downloads.mariadb.com (downloads.mariadb.com)|51.255.94.155|:443... 已             连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:541295045 (516M) [application/octet-stream]
正在保存至: “mariadb-10.2.6-linux-glibc_214-x86_64.tar.gz”

 5% [====>                                                                              7% [==>                                          ] 38,395,559  62.6KB/s 剩余 1h 40m

2、解压并移动

[root@juispan src]# tar zxvfmariadb-10.2.6-linux-glibc_214-x86_64.tar.gz
......
[root@juispan src]# mv mariadb-10.2.6-linux-glibc_214-x86_64 /usr/local/mariadb

3、创建用户

[root@juispan mariadb]# useradd mysql

4、初始化数据库

[root@juispan src]# cd /usr/local/mariadb
[root@juispan mariadb]# ls
bin                 data               include         mysql-test    share
COPYING             DESTINATION        INSTALL-BINARY  README.md     sql-bench
COPYING.thirdparty  docs               lib             README-wsrep  support-files
CREDITS             EXCEPTIONS-CLIENT  man             scripts
[root@server02 mariadb]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mariadb
Installing MariaDB/MySQL system tables in '/data/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 server02 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/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
[root@juispan mariadb]# echo $?
0

初始化显示“OK”和“echo $?”校验都表明了已正常初始化。

5、拷贝配置文件

[root@juispan mariadb]# cp support-files/my-small.cnf /usr/local/mariadb/my.cnf
[root@juispan mariadb]# vi /usr/local/mariadb/my.cnf 
......
basedir         =/usr/local/mariadb
datadir         =/data/mariadb
......

是选用“my-small.conf”还是“my-huge.cnf ”等这种文件和设备的配置有关,根据实际设备配置选择。

6、拷贝启动脚本文件

[root@juispan mariadb]# cp support-files/mysql.server /etc/init.d/mariadb
[root@juispan mariadb]# vi /etc/init.d/mariadb
......
basedir=/usr/local/mariadb      ##定义basedir
datadir=/data/mariadb           ##定义datadir
conf=$basedir/my.cnf            ##定义conf
......
    then
      # Give extra arguments to mysqld with the my.cnf file. This script
      # may be overwritten at next upgrade.
      $bindir/mysqld_safe --defaults-file="$conf"--datadir="$datadir" --pid-file="$mysqld_pid_file_path" "$@" &        ##增加defaults-file启动参数
      wait_for_ready; return_value=$?
......

7、启动Mysql

[root@juispan mariadb]# chkconfig --add mariadb
[root@juispan mariadb]# chkconfig --list

注意:该输出结果只显示 SysV 服务,并不包含原生 systemd 服务。SysV 配置数据可能被原生 systemd 配置覆盖。 
      如果您想列出 systemd 服务,请执行 'systemctl list-unit-files'。
      欲查看对特定 target 启用的服务请执行
      'systemctl list-dependencies [target]'。

mariadb        	0:关	1:关	2:开	3:开	4:开	5:开	6:关
netconsole     	0:关	1:关	2:关	3:关	4:关	5:关	6:关
network        	0:关	1:关	2:开	3:开	4:开	5:开	6:关
[root@juispan mariadb]# /etc/init.d/mariadb start
Reloading systemd:                                         [  确定  ]
Starting mariadb (via systemctl):  Job for mariadb.service failed because the control process exited with error code. See "systemctl status mariadb.service" and "journalctl -xe" for details.
                                                           [失败]
[root@juispan mariadb]# systemctl status mariadb.service
● mariadb.service - LSB: start and stop MySQL
   Loaded: loaded (/etc/rc.d/init.d/mariadb; bad; vendor preset: disabled)
   Active: failed (Result: exit-code) since 五 2017-07-21 08:13:42 CST; 35s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 10559 ExecStart=/etc/rc.d/init.d/mariadb start (code=exited, status=1/FAILURE)

7月 21 08:13:41 juispan mariadb[10559]: Fatal error in defaults handling. Program aborted
7月 21 08:13:41 juispan mariadb[10559]: WARNING: Defaults file '/usr/local/mariadb/my.cnf--datadir=/var/lib/mysql' not found!
7月 21 08:13:41 juispan mariadb[10559]: 170721 08:13:41 mysqld_safe Logging to '/usr/local/mysql/data/juispan.err'.
7月 21 08:13:41 juispan mariadb[10559]: 170721 08:13:41 mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data
7月 21 08:13:41 juispan mariadb[10559]: [147B blob data]
7月 21 08:13:42 juispan mariadb[10559]: ERROR!
7月 21 08:13:42 juispan systemd[1]: mariadb.service: control process exited, code=exited status=1
7月 21 08:13:42 juispan systemd[1]: Failed to start LSB: start and stop MySQL.
7月 21 08:13:42 juispan systemd[1]: Unit mariadb.service entered failed state.
7月 21 08:13:42 juispan systemd[1]: mariadb.service failed.

发现“ Defaults file '/usr/local/mariadb/my.cnf--datadir=/var/lib/mysql' not found!”错误。查看启动脚本,发现定义defaults-file的时候,两个参数之间没有空格导致。

[root@juispan mariadb]# /etc/init.d/mariadb start
Starting mariadb (via systemctl):                          [  确定  ]
[root@juispan mariadb]# netstat -lnpt
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address    Foreign Address         State       PID/Program name
tcp        0      0 0.0.0.0:22       0.0.0.0:*               LISTEN      1337/ssh 
tcp        0      0 127.0.0.1:25     0.0.0.0:*               LISTEN      1863/master     
tcp        0      0 0.0.0.0:873      0.0.0.0:*               LISTEN      2368/rsync      
tcp6       0      0 :::3306          :::*                    LISTEN      3307/mysqld     
tcp6       0      0 :::22            :::*                    LISTEN      1337/sshd       
tcp6       0      0 ::1:25           :::*                    LISTEN      1863/master     
tcp6       0      0 :::873           :::*                    LISTEN      2368/rsync


综上所述:mariadb的安装简直和mysql一模一样。如果服务器上面只有mariadb这个服务,我们完全可以把my.cnf放在etc下,同时也就不需要定义conf以及变量了。