Windows 下以ZIP解壓方式安裝 MariaDB

MariaDB簡(jiǎn)介:

MariaDB是MySQL關(guān)系數(shù)據(jù)庫(kù)管理系統(tǒng)的一個(gè)復(fù)刻,由社區(qū)開(kāi)發(fā),有商業(yè)支持,旨在繼續(xù)保持在GNU GPL下開(kāi)源。MariaDB的開(kāi)發(fā)是由MySQL的一些原始開(kāi)發(fā)者領(lǐng)導(dǎo)的,他們擔(dān)心甲骨文公司收購(gòu)MySQL后會(huì)有一些隱患。MariaDB打算保持與MySQL的高度兼容性。

下載MariaDB

地址:https://downloads.mariadb.org/mariadb/10.5.5/#os_group=windows

image.png
第一步,安裝 MariaDB

解壓壓縮包, 以管理員身份運(yùn)行終端,然后 cd 到解壓后包的bin目錄下運(yùn)行下面命令:

mysql_install_db.exe --service=MariaDB --password=password

這里是將MariaDB安裝,然后設(shè)置為系統(tǒng)服務(wù)并將數(shù)據(jù)庫(kù)的root用戶(hù)的密碼設(shè)置為password, 360安全衛(wèi)士可能會(huì)攔截,你直接選允許即可。運(yùn)行完畢將在你解壓目錄生成data文件夾,里面有數(shù)據(jù)庫(kù)配置文件 my.ini

第二步,啟動(dòng) MariaDB

在終端運(yùn)行

sc start MariaDB

打開(kāi)路徑: 控制面板\所有控制面板項(xiàng)\管理工具\(yùn)服務(wù) 這個(gè)是win10的路徑查看是否啟動(dòng)成功,顯示正在運(yùn)行

image.png
移除數(shù)據(jù)庫(kù)實(shí)例

如果需要卸載MariaDB則按如下命令操作即可:

servicename 為上面注冊(cè)的服務(wù)名稱(chēng) MariaDB
path-to-datadir 默認(rèn)為 data 這個(gè)文件夾

sc stop <servicename>
sc delete <servicename>
rmdir /s /q <path-to-datadir>
第三步,登錄數(shù)據(jù)庫(kù)

密碼默認(rèn)為 剛才設(shè)置的 password

image.png

查看默認(rèn)字符集:

image.png
show variables like 'character%'; 
設(shè)置字符集 utf8mb4

在解壓文件的data目錄找到配置文件 my.ini,使用VS Code等編輯軟件編輯,找到下面相應(yīng)的節(jié)點(diǎn),添加相應(yīng)的內(nèi)容

[client]
default-character-set=utf8mb4

[mysqld]
character-set-client-handshake = false
character_set_server = utf8mb4
character_set_filesystem = binary
character_set_client = utf8mb4
collation_server = utf8mb4_unicode_ci
init_connect='SET NAMES utf8mb4'

[mysqldump]
character_set_client=utf8mb

[mysql]
default-character-set=utf8mb4

保存后,重啟 MariaDB查看是否生效

image.png
為什么要這樣設(shè)置呢?

utf8mb4 和 utf8 的區(qū)別,MySQL 或者 MariaDB 都支持 utf8,但早期的 utf8 為了在性能上取得平衡,其 utf8 只有 3 個(gè)字節(jié),并非標(biāo)準(zhǔn)的 4 字節(jié),如果繼續(xù)使用 3 字節(jié)非標(biāo)準(zhǔn)的 utf8,那么移動(dòng)設(shè)備上的很多符號(hào)將無(wú)法正常顯示,且還會(huì)導(dǎo)致執(zhí)行 SQL 時(shí)異常,所以新版本的 MySQL 和 MariaDB 引入新的編碼格式 utf8mb4 真正支持標(biāo)準(zhǔn)的 UTF-8, utf8mb4 是 utf8 的超集

將MariaDB運(yùn)行路徑注冊(cè)到系統(tǒng)環(huán)境變量中

為了便于在終端使用MariaDB,所以將其注冊(cè)為環(huán)境變量,這樣我們就可以很方便的使用命令行操作數(shù)據(jù)庫(kù)了,否則打開(kāi)終端運(yùn)行時(shí)將會(huì)出現(xiàn)如下錯(cuò)誤:

'mysql' 不是內(nèi)部或外部命令,也不是可運(yùn)行的程序 或批處理文件。
注冊(cè)方法:

我的電腦上右鍵 -> 屬性 -> 高級(jí)系統(tǒng)設(shè)置 -> 環(huán)境變量 -> 選擇 Path 變量,點(diǎn)擊 編輯, 新建 mysql.exe 所在的目錄。

image.png
image.png
添加本機(jī)的MariaDB安裝路徑的bin文件路徑
最后打開(kāi)終端直接輸入mysql命令

附錄:

數(shù)據(jù)庫(kù)可視化管理工具

MySQL Workbench、navicat for mariadb(收費(fèi))

將MariaDB啟動(dòng)安裝為服務(wù)

設(shè)置為 window 系統(tǒng)的服務(wù)手動(dòng)方式:

  1. 創(chuàng)建一個(gè)批處理 install-service.bat 用于將 MariaDB 安裝為服務(wù)
::指定創(chuàng)建服務(wù)的程序
@set mariadb_service="x:\mariadb\xxx\bin\mysqld.exe"
::設(shè)置服務(wù)名
@set service_name="MariaDB"

::開(kāi)始安裝Mariadb服務(wù)
%mariadb_service% --install %service_name% --defaults-file="x:\mariadb\xxx\bin\my.ini"

pause

  1. 再創(chuàng)建一個(gè)移除服務(wù)的批處理 uninstall-service.bat
@set mariadb_service="x:\mariadb\xxx\bin\mysqld.exe"
@set service_name="MariaDB"

:: 卸載服務(wù)
%mariadb_service% --remove %service_name%

pause

mysql_install_db.exe 的命令行說(shuō)明文檔

The functionality of mysql_install_db.exe is comparable with the shell script mysql_install_db used on Unix, however it has been extended with both Windows specific functionality (creating a Windows service) and to generally useful functionality. For example, it can set the 'root' user password during database creation. It also creates the my.ini configuration file in the data directory and adds most important parameters to it (e.g port).

mysql_install_db.exe is used by the MariaDB installer for Windows if the "Database instance" feature is selected. It obsoletes similar utilities and scripts that were used in the past such as mysqld.exe --install, mysql_install_db.pl, and mysql_secure_installation.pl.

image.png

Note : to create a Windows service, mysql_install_db.exe should be run by a user with full administrator privileges (which means elevated command prompt on systems with UAC). For example, if you are running it on Windows 7, make sure that your command prompt was launched via 'Run as Administrator' option.

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀(guān)點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容