二進位安裝mariaDB

來源:互聯網
上載者:User

標籤:safe   scripts   res   run   medium   記憶體   x86   monitor   wan   

1.擷取二進位安裝包

擷取二進位格式MariaDB安裝包,可去官網下載.

因為是實驗環境,所以選擇了最新版.

mariadb-10.2.12-linux-x86_64.tar.gz


2.解壓

解壓到 /usr/local,並給解壓出的檔案夾建立軟串連

]# tar xf mariadb-10.2.12-linux-x86_64.tar.gz -C /usr/local/]# cd /usr/local/]# ln -sv mariadb-10.2.12-linux-x86_64/ mysql]# ll mysqllrwxrwxrwx. 1 root root 29 Jan 23 10:33 mysql -> mariadb-10.2.12-linux-x86_64/


3.建立帳戶

為mariaDB建立一個系統使用者,屬主為root,數組為mysql

]# groupadd -r mysql]# cat /etc/group | grep mysqlmysql:x:985:]# cd mysql

ll查看發現所有檔案的屬主屬組都只顯示id號

針對軟串連,要用下面的方式修改其中的檔案屬性

]# chown -R root:mysql ./*]# lltotal 180drwxrwxr-x. 2 root mysql 4096 Nov 14 22:34 bin......


4.準備文檔目錄

為了管理方便,專門指定並建立幾個專用目錄

存放資料庫的目錄/mdata/data

存放設定檔的目錄/etc/mysql

]# mkdir -pv /mdata/data

修改這個目錄的屬主屬組為mysql

]# useradd -r mysql -g mysql -s /bin/nologin]# chown -R mysql.mysql /mdata]# mkdir /etc/mysql


5.設定檔

mariaDB的主設定檔是/etc/my.cnf.其中include包含了/etc/my.cnf.d這個目錄

]# cat /etc/my.cnf[mysqld]datadir=/var/lib/mysqlsocket=/var/lib/mysql/mysql.sock# Disabling symbolic-links is recommended to prevent assorted security riskssymbolic-links=0# Settings user and group are ignored when systemd is used.# If you need to run mysqld under a different user or group,# customize your systemd unit file for mariadb according to the# instructions in http://fedoraproject.org/wiki/Systemd[mysqld_safe]log-error=/var/log/mariadb/mariadb.logpid-file=/var/run/mariadb/mariadb.pid## include all files from the config directory#!includedir /etc/my.cnf.d

support-files/目錄下有5個針對不同系統記憶體設定的設定檔範本

]# ls /usr/local/mysql/support-files/my-*my-huge.cnf my-innodb-heavy-4G.cnf my-large.cnf my-medium.cnf my-small.cnf

其中

my-small.cnf適用於記憶體只有64M;

my-medium.cnf適用於記憶體只有256M;

my-large.cnf適用於記憶體只有512M;

my-huge.cnf適用於更大記憶體,如2G、4G;

my-innodb-heavy-4G.cnf適用於4G記憶體;


實驗用主機有2g記憶體,所以使用my-huge.cnf

把my-huge.cnf複製到自訂設定檔目錄下並重新命名為my.cnf,並在[mysqld]代碼塊中新增內容

]# cp support-files/my-huge.cnf /etc/mysql/my.cnf]# vim /etc/mysql/my.cnfdatadir = /mdata/data #指定資料庫目錄skip_name_resolve = ON #忽略反解主機名稱innodb_file_per_table = ON #開啟獨立資料表空間,預設是所有資料庫放在同一個檔案中,ON的話會把每個資料庫單獨放一個檔案


6.建立資料庫檔案

必須在/usr/local/mysql目錄下操作,否則會報錯

]# cd /usr/local/mysql]# ./scripts/mysql_install_db --datadir=/mdata/data --user=mysql
7.建立記錄檔
 
]# touch /var/log/mysqld.log]# chown mysql:mysql /var/log/mysqld.log 

8.準備服務指令碼,啟動服務

先通過support-files/mysql.server 啟動mysql

./support-files/mysql.server start

成功後,通過ps命令查看

]# ps -ef|grep mysql

找到--pid-file=/mdata/data/centos7.qt.pid字樣 記住pid路徑和名稱/mdata/data/centos7.qt.pid

在/usr/lib/systemd/system目錄下增建立mysql.service,內容如下

]# vim /usr/lib/systemd/system/mysql.service[Unit]Description=MysqlAfter=syslog.target network.target remote-fs.target nss-lookup.target[Service]Type=forkingPIDFile=/mdata/data/centos7.qt.pidExecStart=/usr/local/mysql/support-files/mysql.server startExecReload=/bin/kill -s HUP $MAINPIDExecStop=/bin/kill -s QUIT $MAINPIDPrivateTmp=false[Install]WantedBy=multi-user.targetPIDFile=/mdata/data/centos7.qt.pid  #就是跟上上面記錄的內容


執行重新掃描,載入有變化的單元,使服務生效,之後便可以通過systemctl操作

]# systemctl daemon-reload]# systemctl start mysql


9.進行安全初始化設定

運行指令碼

]# /usr/local/mysql/bin/mysql_secure_installation


10.設定環境變數
]# echo ‘PATH=/usr/local/mysql/bin:$PATH‘ > /etc/profile.d/mysql.sh]# . /etc/profile.d/mysql.sh


11.啟動mysql
]# mysql -uroot -pEnter password: Welcome to the MariaDB monitor. Commands end with ; or \g.Your MariaDB connection id is 19Server version: 10.2.12-MariaDB-log MariaDB ServerCopyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.MariaDB [(none)]> 

二進位安裝mariaDB

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.