centos編譯安裝mariadb的詳細過程
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內容請搜索WalkonNet以前的文章或繼續瀏覽下面的相關文章希望大傢以後多多支持WalkonNet!
推薦閱讀:
- MySQL系列之一 MariaDB-server安裝
- MySQL系列之三 基礎篇
- MySQL系列之二 多實例配置
- Centos7下安裝MySQL8.0.23的步驟(小白入門級別)
- 從mysql讀寫分離著手提升服務器性能