網(wǎng)站首頁 編程語言 正文
centos編譯安裝mariadb
一般我不太愿意用mysql,那個(gè)玩意,有的時(shí)候不太友好。
我還是比較喜歡mariadb。
1:安裝cmake環(huán)境
安裝MariaDB之前,首先要安裝cmake,另外為了保證不缺依賴,使用yum或者rpm安裝依賴:readline-devel,zlib-devel,openssl-devel,libaio-devel并且readline-devel依賴于ncurses-devel,如果使用yum的話會(huì)自動(dòng)將所需依賴安裝好,具體命令如下:
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):進(jìn)入/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):進(jìn)入cmark的源碼目錄
cd cmake
-3.12.0
-rc1
(5):運(yùn)行當(dāng)前目錄下的一個(gè)文件
./bootstrap
(6):編譯并安裝(時(shí)間稍長)
gmake&&gmake install
(7):查看版本號(hào)
cmake --version
2:安裝mariadb
這個(gè)安裝和php及nginx的安裝類似,只是mariadb的編譯是使用cmake
這里提前預(yù)定mysql的安裝目錄為/usr/local/mariadb并且數(shù)據(jù)表文件目錄為/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):創(chuàng)建用戶及用戶組
groupadd mysql
useradd -s /sbin/nologin -r -g mysql mysql
(3):解壓、預(yù)編譯、編譯安裝
# 解壓
tar -zxvf mariadb-10.5.6.tar.gz
# 進(jìn)入目錄
cd mariadb-10.5.6
# 預(yù)編譯,將與
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):配置啟動(dòng)文件及權(quán)限等
# 進(jìn)入安裝目錄
cd /usr/local/mariadb/
# 創(chuàng)建啟動(dòng)文件
cp support-files/mysql.server /etc/init.d/mysqld
# 添加執(zhí)行權(quán)限
chmod +x /etc/init.d/mysqld
# 創(chuàng)建存放數(shù)據(jù)表目錄
mkdir -p mkdir /usr/local/mariadb/mysqldata/
# 創(chuàng)建存放mysql.sock目錄
mkdir -p mkdir /usr/local/mariadb/tmp/
# 修改mariadb目錄權(quán)限
chown -R mysql:mysql /usr/local/mariadb/
# 創(chuàng)建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
# 刪除默認(rèn)mariadb配置文件(默認(rèn)加載默認(rèn)的my.cnf文件,不刪除,啟動(dòng)會(huì)報(bào)錯(cuò))
rm -rf /etc/my.cnf
(5):數(shù)據(jù)初始化
/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目錄下的所有文件權(quán)限都是mysql
chown -R mysql:mysql /usr/local/mariadb/
(8):啟動(dòng)mysql
至此,mariadb安裝成功,現(xiàn)在,我們來啟動(dòng)數(shù)據(jù)庫:
/etc/init.d/mysqld start
啟動(dòng)成功:
[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操作命令
默認(rèn)操作mariadb命令:
/usr/local/mariadb/bin/mysql
比較長,用著不太方便,簡化方式其實(shí)和php是一樣的:
vim /root/.bash_profile
添加內(nèi)容:
alias mysql=/usr/local/mariadb/bin/mariadb
修改完成,重載一下文件:
source /root/.bash_profile
或者創(chuàng)建軟連接
ln -s /usr/local/mariadb/bin/mariadb /usr/bin/mariadb
(10):鏈接mariadb
Mariadb默認(rèn)沒有密碼,所以直接使用
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)]>
數(shù)據(jù)庫的其他配置,請移步《Centos7.6配置lnmp》
(11):重啟服務(wù)器,運(yùn)行mariadb報(bào)錯(cuò):
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/usr/local/mariadb/tmp/mysql.sock' (2)
原因是找不到本地套接字文件mysql.sock
默認(rèn)位置是在/tmp/mysql.sock,但是我這里在my.cnf中配置了其位置:
在/usr/local/mariadb/tmp/mysql.sock
查看當(dāng)前目錄下是否有該文件,沒有的話,重新啟動(dòng)mariadb,會(huì)自動(dòng)生成mysql.sock文件,不要自己手動(dòng)創(chuàng)建。
使用如下命令:(該命令,是我在安裝時(shí)已配置好)
/etc/rc.d/init.d/mysqld restart
(12):設(shè)置開機(jī)啟動(dòng)
確保rc.local?文件有執(zhí)行權(quán)限,否則,開機(jī)啟動(dòng)不生效
vim /etc/rc.d/rc.local
添加如下內(nèi)容:
/etc/rc.d/init.d/mysqld restart
至此,centos編譯安裝mariadb完成。
我這里都是指定位置安裝,配置文件都在安裝目錄下,因此刪除的時(shí)候相對比較方便。
升級的情況,之后要升級的時(shí)候會(huì)在寫。
卸載軟件的話,直接刪除目錄就好。
原文鏈接:https://juejin.cn/post/7137110573380009997
相關(guān)推薦
- 2023-02-03 python關(guān)于excel多個(gè)sheet的導(dǎo)入導(dǎo)出方式_python
- 2022-04-28 sql?server?累計(jì)求和實(shí)現(xiàn)代碼_MsSql
- 2022-10-21 使用nginx進(jìn)行負(fù)載均衡的搭建全過程_nginx
- 2022-09-27 Swift超詳細(xì)講解指針_Swift
- 2022-10-27 go?熔斷原理分析與源碼解讀_Golang
- 2022-05-22 C語言鏈接屬性的實(shí)踐應(yīng)用_C 語言
- 2022-03-22 .NET?6中間件Http?Logging使用介紹_實(shí)用技巧
- 2022-06-26 django中模板繼承與ModelForm實(shí)例詳解_python
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細(xì)win安裝深度學(xué)習(xí)環(huán)境2025年最新版(
- Linux 中運(yùn)行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲(chǔ)小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎(chǔ)操作-- 運(yùn)算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認(rèn)證信息的處理
- Spring Security之認(rèn)證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權(quán)
- redisson分布式鎖中waittime的設(shè)
- maven:解決release錯(cuò)誤:Artif
- restTemplate使用總結(jié)
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實(shí)現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務(wù)發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據(jù)結(jié)構(gòu)-簡單動(dòng)態(tài)字符串(SD
- arthas操作spring被代理目標(biāo)對象命令
- Spring中的單例模式應(yīng)用詳解
- 聊聊消息隊(duì)列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠(yuǎn)程分支