mariadb
MariaDB数据库管理系统是MySQL的一个分支,主要由开源社区在维护,采用GPL授权许可 MariaDB的目的是完全兼容MySQL,包括API和命令行,使之能轻松成为MySQL的代替品。在存储引擎方面,使用XtraDB来代替MySQL的InnoDB。 MariaDB由MySQL的创始人Michael Widenius主导开发,他早前曾以10亿美元的价格,将自己创建的公司MySQL AB卖给了SUN,此后,随着SUN被甲骨文收购,MySQL的所有权也落入Oracle的手中。MariaDB名称来自Michael Widenius的女儿Maria的名字。
download mariadb
mariadb | mariadb(RPM) | mysql workbench | 文档 |
download | 官网 | download | 参考 参考 |
前提条件
- 开启wmi,配置网卡,参考
mariadb 10.11 一键自动化部署编写
- 最终实现在线下载mariadb二进制包,解压重命名,创建数据目录,创建数据配置my.ini环境变量设置,初始化数据库,创建库,创建用户,创建用户权限,远程连接设置,版本获取,安装完成删除包,防火墙设置。
- C:\mariadb 安装位置
- C:\mariadb\data 数据目录
- root/Report@123 mariadb数据库登录管理员
- mar/Report@123 此账号是自定义创建的管理员,生产环境删除哦
- mariadb_test 创建的临时数据库
- C:\mariadb\data\my.ini 数据库配置文件
- mysqldump.exe -uroot -pReport@123 --lock-all-tables --all-databases --events > c:\mysql_dump.sql 备份数据库操作
- mysql -u root -pReport@123 < c:\mysql_dump.sql 导入数据库
- mysql_install_db.exe 安装参数参考
- if 判断是否存在psql 命令 if (-not (Get-Command mysql -ErrorAction SilentlyContinue))
- 依赖VisualC++ ,所有包含历史版下载
- increase indent:Tab
- decrease indent:Shift+Tab
powershell-install-mariadb.ps1
<# Powershell Install mariadb
+++++++++++++++++++++++++++++++++++++++++++++++++++++
+ _____ _____ _ _ _ +
+ | __ \ / ____| | | | |+
+ | |__) |____ _____ _ _| (___ | |__ ___| | |+
+ | ___/ _ \ \ /\ / / _ \ '__\___ \| '_ \ / _ \ | |+
+ | | | (_) \ V V / __/ | ____) | | | | __/ | |+
+ |_| \___/ \_/\_/ \___|_| |_____/|_| |_|\___|_|_|+
+ +++++++++++++++++++++++++++++++++++++++++++++++++++
# mysql_install_db.exe install Basic
https://mariadb.com/kb/en/mysql_install_dbexe/
# Powershell Install mariadb
# .\powershell-install-mariadb.ps1
#>
function Install-mariadb {
if (-not (Get-Command mysql -ErrorAction SilentlyContinue)) {
if ($?) {
$drive = "c:"
$mariadb_temporary = "mariadb_temporary"
$mariadb = "mariadb"
$mariadb_data = "data"
#mariadb configuration files
$mysql_root_password = "Repot@123"
$mysql_port = "3306"
$mysql_my_ini = "my.ini"
$mysql_socket = "mysql.sock"
#mariadb packag
$mariadb_zip = "mariadb-10.11.3-winx64.zip"
$vc_redist_64 = "vc_redist.x64.exe"
$vc_redist_86 = "vc_redist.x86.exe"
$mariadb_decompression_directory = "mariadb-10.11.3-winx64"
Write-Host "Create a directory for storing mariadb temporary" -ForegroundColor Green
New-Item -ItemType Directory $drive\$mariadb_temporary
$mariadb_related_download = @(
"https://archive.mariadb.org/mariadb-10.11.3/winx64-packages/$mariadb_zip",
"https://aka.ms/vs/17/release/$vc_redist_64",
"https://aka.ms/vs/17/release/$vc_redist_86"
)
foreach ($url in $mariadb_related_download) {
$fileName = Split-Path $url -Leaf
$filePath = Join-Path $drive\$mariadb_temporary $fileName
Invoke-WebRequest -Uri $url -OutFile $filePath
}
Write-Host "install vc_redist x86 x64" -ForegroundColor Green
Start-Process -FilePath "$drive\$mariadb_temporary\$vc_redist_64" -ArgumentList {/q /install} -Wait
Start-Process -FilePath "$drive\$mariadb_temporary\$vc_redist_86" -ArgumentList {/q /install} -Wait
Write-Host "Unzip the mariadb package" -ForegroundColor Green
Expand-Archive -Path $drive\$mariadb_temporary\$mariadb_zip -DestinationPath $drive\
Write-Host "Rename the mariadb folder name" -ForegroundColor Green
Rename-Item -Path $drive\$mariadb_decompression_directory -NewName $mariadb
Write-Host "Create a directory for storing database data" -ForegroundColor Green
New-Item -ItemType Directory "$drive\$mariadb\$mariadb_data"
Write-Host "Create mariadb environment variables" -ForegroundColor Green
$env:path += ";$drive\$mariadb\bin"
setx PATH $env:path /M
Write-Host "mysql ini configuration" -ForegroundColor Green
$functionText = @"
[client]
port=$mysql_port
plugin-dir=$drive\$mariadb\lib\plugin
default-character-set=utf8mb4
[mysqld]
datadir=$drive\$mariadb\$mariadb_data
basedir=$drive\$mariadb
port=$mysql_port
max_connections=200
character_set_server=utf8mb4
collation-server=utf8mb4_unicode_ci
character-set-client-handshake=FALSE
default-storage-engine=INNODB
default-time_zone='+8:00'
log_bin_trust_function_creators = on
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
lower_case_table_names=1
[mysql]
default-character-set=utf8mb4
"@
New-Item "$drive\$mariadb\$mysql_my_ini" -type file -force -value $functionText
Write-Host "initialize mariadb" -ForegroundColor Green
mysql_install_db --config=$drive\$mariadb\$mysql_my_ini --datadir=$drive\$mariadb\$mariadb_data --socket=$mysql_socket --service=$mariadb --password=$mysql_root_password
Write-Host "start mariadb" -ForegroundColor Green
Start-Service $mariadb
Write-Host "Viewing mysql process port" -ForegroundColor Green
netstat -ano|findstr $mysql_port
Test-NetConnection -ComputerName localhost -Port $mysql_port | Select-Object -ExpandProperty TcpTestSucceeded
Get-Service -Name $mariadb | Select-Object -ExpandProperty Status
Write-Host "check mariadb version" -ForegroundColor Green
mysql -V
Write-Host "Allow root to log in remotely" -ForegroundColor Green
mysql -uroot -p$mysql_root_password -e "GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'Report@123' WITH GRANT OPTION;"
Write-Host "Create a user and assign the user login permission, super user permission, super role permission, database creation permission, replication permission, and backup permission" -ForegroundColor Green
mysql -uroot -p$mysql_root_password -e "CREATE DATABASE mariadb_test;"
mysql -uroot -p$mysql_root_password -e "CREATE USER mar@'%' IDENTIFIED BY 'Report@123';"
mysql -uroot -p$mysql_root_password -e "GRANT ALL PRIVILEGES ON *.* TO mar@'%' WITH GRANT OPTION;"
mysql -uroot -p$mysql_root_password -e "GRANT SUPER ON *.* TO mar@'%';"
Write-Host "firewall mariadb port" -ForegroundColor Green
New-NetFirewallRule -DisplayName $mariadb -Direction Outbound -profile any -LocalPort $mariadb_port -Protocol TCP -Action Allow
New-NetFirewallRule -DisplayName $mariadb -Direction Inbound -profile any -LocalPort $mariadb_port -Protocol TCP -Action Allow
Write-Host "Delete related mariadb packages and temporary directories" -ForegroundColor Green
Remove-Item -Path "$drive\$mariadb_temporary\*.exe", "$drive\$mariadb_temporary", "$drive\$mariadb\$mysql_my_ini" -Recurse -Force
Write-Host "The mariadb Install Success..." -ForegroundColor Green
} else {
Write-Host "The mariadb Install Failed..." -ForegroundColor Red
exit 1
}
} else {
Write-Host "The mariadb Install already..." -ForegroundColor Yellow
}
}
function Main {
Install-mariadb
}
Main
执行安装mariadb
.\powershell-install-mariadb.ps1
输出结果展示