首頁 > 軟體

centos編譯安裝mariadb的詳細過程

2022-08-29 22:01:44

centos編譯安裝mariadb

一般我不太願意用mysql,那個玩意,有的時候不太友好。

我還是比較喜歡mariadb。

1:安裝cmake環境

安裝MariaDB之前,首先要安裝cmake,另外為了保證不缺依賴,使用yum或者rpm安裝依賴:readline-devel,zlib-devel,openssl-devel,libaio-devel並且readline-devel依賴於ncurses-devel,如果使用yum的話會自動將所需依賴安裝好,具體命令如下:

yum -y install readline-devel
yum -y install zlib-devel
yum -y install openssl-devel
yum -y install libaio-devel
yum -y install ncurses-devel

(1):進入/usr/local/download/目錄

cd /usr/local/download

(2):解壓原始碼包

wget 
https:
//cmake.org/files/v3.12/cmake-3.12.0-rc1.tar.gz

(cmake.org/files/v3.12…)

(3):解壓CMake原始碼包

tar -zxvf cmake
-3.12.0
-rc1.tar.gz

(4):進入cmark的原始碼目錄

cd cmake
-3.12.0
-rc1

(5):執行當前目錄下的一個檔案

./bootstrap

(6):編譯並安裝(時間稍長)

gmake&&gmake install

(7):檢視版本號

cmake --version

2:安裝mariadb

這個安裝和php及nginx的安裝類似,只是mariadb的編譯是使用cmake

這裡提前預定mysql的安裝目錄為/usr/local/mariadb並且資料表檔案目錄為/usr/local/mariadb /mysqldata,

(1):下載

cd /usr/local/download
wget https://downloads.mariadb.org/f/mariadb-10.5.6/source/mariadb-10.5.6.tar.gz

(2):建立使用者及使用者組

groupadd mysql
useradd -s /sbin/nologin -r -g mysql mysql

(3):解壓、預編譯、編譯安裝

# 解壓
tar -zxvf mariadb-10.5.6.tar.gz
# 進入目錄
cd mariadb-10.5.6
# 預編譯,將與
cmake -j . 
-DCMAKE_INSTALL_PREFIX=/usr/local/mariadb 
-DMYSQL_DATADIR=/usr/local/mariadb/mysqldata/ 
-DSYSCONFDIR=/usr/local/mariadb 
-DMYSQL_USER=mysql 
-DMYSQL_TCP_PORT=3306 
-DWITHOUT_TOKUDB=1 
-DMYSQL_UNIX_ADDR=/usr/local/mariadb/tmp/mysql.sock 
-DDEFAULT_CHARSET=utf8 
-DDEFAULT_COLLATION=utf8_general_ci
 
# 編譯安裝
make&&make install

(4):設定啟動檔案及許可權等

# 進入安裝目錄
cd /usr/local/mariadb/
# 建立啟動檔案
cp support-files/mysql.server /etc/init.d/mysqld
# 新增執行許可權
chmod +x /etc/init.d/mysqld
# 建立存放資料表目錄
mkdir -p mkdir /usr/local/mariadb/mysqldata/
# 建立存放mysql.sock目錄
mkdir -p mkdir /usr/local/mariadb/tmp/
# 修改mariadb目錄許可權
chown -R mysql:mysql /usr/local/mariadb/
# 建立mariadb組態檔
vim /usr/local/mariadb/my.cnf
[mysqld]
basedir=/usr/local/mariadb/
datadir=/usr/local/mariadb/mysqldata/
port=3306
pid-file=/usr/local/mariadb/mysqldata/mysql.pid
socket=/usr/local/mariadb/tmp/mysql.sock
 
[mysqld_safe]
log-error=/usr/local/mariadb/mysqldata/mysql.log
 
[client]
port=3306
socket=/usr/local/mariadb/tmp/mysql.sock
default-character-set=utf8
 
# 刪除預設mariadb組態檔(預設載入預設的my.cnf檔案,不刪除,啟動會報錯)
rm -rf /etc/my.cnf

(5):資料初始化

/usr/local/mariadb/scripts/mysql_install_db --datadir=/usr/local/mariadb/mysqldata

初始化成功:

[root@iZuf60ynur81p6k0ysvtneZ mariadb]# /usr/local/mariadb/scripts/mysql_install_db --datadir=/usr/local/mariadb/mysqldata
Installing MariaDB/MySQL system tables in '/usr/local/mariadb/mysqldata' ...
OK
 
To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system
 
 
Two all-privilege accounts were created.
One is root@localhost, it has no password, but you need to
be system 'root' user to connect. Use, for example, sudo mysql
The second is root@localhost, it has no password either, but
you need to be the system 'root' user to connect.
After connecting you can set the password, if you would need to be
able to connect as any of these users with a password and without sudo
 
See the MariaDB Knowledgebase at https://mariadb.com/kb or the
MySQL manual for more instructions.
 
You can start the MariaDB daemon with:
cd '.' ; ./bin/mysqld_safe --datadir='/usr/local/mariadb/mysqldata'
 
You can test the MariaDB daemon with mysql-test-run.pl
cd './mysql-test' ; perl mysql-test-run.pl
 
Please report any problems at https://mariadb.org/jira
 
The latest information about MariaDB is available at https://mariadb.org/.
You can find additional information about the MySQL part at:
https://dev.mysql.com
Consider joining MariaDB's strong and vibrant community:
https://mariadb.org/get-involved/

(7):確保/usr/local/mariadb目錄下的所有檔案許可權都是mysql

chown -R mysql:mysql /usr/local/mariadb/

(8):啟動mysql

至此,mariadb安裝成功,現在,我們來啟動資料庫:

/etc/init.d/mysqld start

啟動成功:

[root@iZuf60ynur81p6k0ysvtneZ mariadb]# /etc/init.d/mysqld start
Starting MariaDB.201015 17:26:58 mysqld_safe Logging to '/usr/local/mariadb/mysqldata/mysql.log'.
201015 17:26:58 mysqld_safe Starting mariadbd daemon with databases from /usr/local/mariadb/mysqldata
                                                           [  OK  ]

(9):簡化mariadb操作命令

預設操作mariadb命令:

/usr/local/mariadb/bin/mysql

比較長,用著不太方便,簡化方式其實和php是一樣的:

vim /root/.bash_profile

新增內容:

alias mysql=/usr/local/mariadb/bin/mariadb

修改完成,過載一下檔案:

source /root/.bash_profile

或者建立軟連線

ln -s /usr/local/mariadb/bin/mariadb /usr/bin/mariadb

(10):連結mariadb

Mariadb預設沒有密碼,所以直接使用

mysql -uroot -p
如下所示:
[root@iZuf60ynur81p6k0ysvtneZ mariadb]# mysql -uroot -p
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or g.
Your MariaDB connection id is 6
Server version: 10.5.6-MariaDB Source distribution
 
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
 
Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.
 
MariaDB [(none)]>

資料庫的其他設定,請移步《Centos7.6設定lnmp》

(11):重啟伺服器,執行mariadb報錯:

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/usr/local/mariadb/tmp/mysql.sock' (2)

原因是找不到本地通訊端檔案mysql.sock

預設位置是在/tmp/mysql.sock,但是我這裡在my.cnf中設定了其位置:

在/usr/local/mariadb/tmp/mysql.sock

檢視當前目錄下是否有該檔案,沒有的話,重新啟動mariadb,會自動生成mysql.sock檔案,不要自己手動建立。

使用如下命令:(該命令,是我在安裝時已設定好)

/etc/rc.d/init.d/mysqld restart

(12):設定開機啟動

確保rc.local 檔案有執行許可權,否則,開機啟動不生效

vim /etc/rc.d/rc.local

新增如下內容:

/etc/rc.d/init.d/mysqld restart

至此,centos編譯安裝mariadb完成。

我這裡都是指定位置安裝,組態檔都在安裝目錄下,因此刪除的時候相對比較方便。

升級的情況,之後要升級的時候會在寫。

解除安裝軟體的話,直接刪除目錄就好。

到此這篇關於centos編譯安裝mariadb的文章就介紹到這了,更多相關centos編譯安裝mariadb內容請搜尋it145.com以前的文章或繼續瀏覽下面的相關文章希望大家以後多多支援it145.com!


IT145.com E-mail:sddin#qq.com