Mariadb安裝
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、下載安裝文件
[[email protected] 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、解壓並移動
[[email protected] src]# tar zxvfmariadb-10.2.6-linux-glibc_214-x86_64.tar.gz ...... [[email protected] src]# mv mariadb-10.2.6-linux-glibc_214-x86_64 /usr/local/mariadb
3、創建用戶
[[email protected] mariadb]# useradd mysql
4、初始化數據庫
[[email protected] src]# cd /usr/local/mariadb [[email protected]
初始化顯示“OK”和“echo $?”校驗都表明了已正常初始化。
5、拷貝配置文件
[[email protected] mariadb]# cp support-files/my-small.cnf /usr/local/mariadb/my.cnf [[email protected] mariadb]# vi /usr/local/mariadb/my.cnf ...... basedir =/usr/local/mariadb datadir =/data/mariadb ......
是選用“my-small.conf”還是“my-huge.cnf ”等這種文件和設備的配置有關,根據實際設備配置選擇。
6、拷貝啟動腳本文件
[[email protected] mariadb]# cp support-files/mysql.server /etc/init.d/mariadb [[email protected] 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
[[email protected] mariadb]# chkconfig --add mariadb [[email protected] 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:關 [[email protected] 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. [失敗] [[email protected] 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的時候,兩個參數之間沒有空格導致。
[[email protected] mariadb]# /etc/init.d/mariadb start Starting mariadb (via systemctl): [ 確定 ] [[email protected] 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以及變量了。
本文出自 “A man & A computer” 博客,請務必保留此出處http://juispan.blog.51cto.com/943137/1951282
Mariadb安裝