本篇內容介紹了“centos怎么編譯安裝mariadb”的有關知識,在實際案例的操作過程中,不少人都會遇到這樣的困境,接下來就讓小編帶領大家學習一下如何處理這些情況吧!希望大家仔細閱讀,能夠學有所成!
一般我不太愿意用mysql,那個玩意,有的時候不太友好。
我還是比較喜歡mariadb。
安裝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
cd /usr/local/download
wget https: //cmake.org/files/v3.12/cmake-3.12.0-rc1.tar.gz
(cmake.org/files/v3.12…)
tar -zxvf cmake -3.12.0 -rc1.tar.gz
cd cmake -3.12.0 -rc1
./bootstrap
gmake&&gmake install
cmake --version
這個安裝和php及nginx的安裝類似,只是mariadb的編譯是使用cmake
這里提前預定mysql的安裝目錄為/usr/local/mariadb并且數據表文件目錄為/usr/local/mariadb /mysqldata,
cd /usr/local/download wget https://downloads.mariadb.org/f/mariadb-10.5.6/source/mariadb-10.5.6.tar.gz
groupadd mysql useradd -s /sbin/nologin -r -g mysql mysql
# 解壓 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
# 進入安裝目錄 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
/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/
chown -R mysql:mysql /usr/local/mariadb/
至此,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 ]
默認操作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
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)]>
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
確保rc.local 文件有執行權限,否則,開機啟動不生效
vim /etc/rc.d/rc.local
添加如下內容:
/etc/rc.d/init.d/mysqld restart
至此,centos編譯安裝mariadb完成。
我這里都是指定位置安裝,配置文件都在安裝目錄下,因此刪除的時候相對比較方便。
升級的情況,之后要升級的時候會在寫。
卸載軟件的話,直接刪除目錄就好。
“centos怎么編譯安裝mariadb”的內容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業相關的知識可以關注億速云網站,小編將為大家輸出更多高質量的實用文章!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。