Download and run MariaDB installer

Welcome Forums General PowerShell Q&A Download and run MariaDB installer

Viewing 13 reply threads
  • Author
    Posts
    • #196391
      Participant
      Topics: 3
      Replies: 11
      Points: 55
      Rank: Member

      Hi ,

      Did you ever try to download and install MariaDb from powershell ?

      Below is the link for the last release

      https://downloads.mariadb.org/interstitial/mariadb-10.4.11/winx64-packages/mariadb-10.4.11-winx64.msi/from/http%3A//download.nus.edu.sg/mirror/mariadb/

      This is the code that I use

      bitsadmin.exe /transfer $Job  /dynamic /download /priority FOREGROUND $Link $Target 
      $target is equal to  “c:\tmp\mariadb-10.4.11-winx64.msi”

      It starts to download it but stops just after 9kbyte.

      Below is part of link , it’s a ftp. I tried to downlod directly from that ftp but I get a “Access denied” message

      http%3A//download.nus.edu.sg/mirror/mariadb/

      maybe this question is not related to powershell , but I just try to ask

      Thank

    • #196397
      Participant
      Topics: 5
      Replies: 2411
      Points: 6,193
      Helping Hand
      Rank: Community MVP
    • #196400
      Participant
      Topics: 3
      Replies: 11
      Points: 55
      Rank: Member

      I’ve found that link here https://downloads.mariadb.org/mariadb/10.4.11/  😐

      I choose Bits for the progress bar  , What Do you suggest ? 🙂

       

       

       

    • #196439
      Participant
      Topics: 5
      Replies: 2411
      Points: 6,193
      Helping Hand
      Rank: Community MVP

      I choose Bits for the progress bar , What Do you suggest ? 🙂

      Does the download work without BITS?

      IMHO: For me working with Powershell is always about automation and running stuff in the background. I rarely provide tools for others containing actions running long enough to be worth having some kind of entertaining while you’re waiting for something … like a progressbar. If something takes that long I wouldn’t try to make that more enjoyable. I would try to make it faster – to make it less anoying. 😉 … the download of the mariadb installer takes about 10 to 15 seconds for me. I would suggest not to spend that much effort to get a nice progressbar and make it pretty. I would suggest to spend the effort to make it fast, reliable and fault tolerant. 😉

    • #196445
      Participant
      Topics: 3
      Replies: 11
      Points: 55
      Rank: Member

      +1

      I agree, especially for ‘fault tolerant’

      Thank Olaf

    • #196448
      Participant
      Topics: 3
      Replies: 11
      Points: 55
      Rank: Member

      Hi again ,

      I’ve tried many time , but I can’t run a script as admin from another script

      function set-MariaDbservice {
       If (-NOT ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator"))
       {
          Write-Host "MariaDB service needs to be run As Admin" -ForegroundColor Red
          Write-Host -nonewline "Continue? (Y/N) "
          $answ = read-host
          if ( $answ -ne "Y" ) { exit }
       }
          Start-Process powershell  -ArgumentList '-noExit -noprofile -file Start_MariaDB.ps1 ' -verb RunAs
      }

      I have to run  `mysql_install_db.exe`  as Admin in order to config it and then start the service

      When the Start-Pocess run the Start_MariaDB it quicky open and close a new window with no output or error.

      I’ve tried with : -noExit, prompt , sleep,Pause, -ExecutionPolicy Bypass ( but it’s Admin so it doesn’t matter)

      Start_MariaDB.ps1 code

      $installDrive               = "C:\Db"

      function set-MariaDbservice {
      Write-Host "New folder -> " $installDrive  -ForegroundColor Green
      new-item $installDrive -itemtype directory | Out-Null
        $arg1 =   "--datadir=" + $installDrive
        $arg2 =   "--service=DB"
        $arg3 =   "--password=powershell"
        $allArgs = @($arg1,$arg2,$arg3)
        Start-Process  -FilePath "mysql_install_db.exe" $allArgs -Wait -NoNewWindow
      }
      set-MariaDbservice
      Start-Sleep 10
      write-host -nonewline "Continue? (Y/N) "
      $response = read-host
      if ( $response -ne "Y" ) { exit }
      Pause

      That code doesnt work , the exe file doesnt’t run. I can only see a open and close window with blue background

      Thank

    • #196451
      Participant
      Topics: 5
      Replies: 2411
      Points: 6,193
      Helping Hand
      Rank: Community MVP

      Who is supposed to run this script? Installing a database should be the task for administrators anyway. If the user has sufficient rights (administrative rights) it should be enough to use the statement #Requires -RunAsAdministrator at the top of the script. This would prevent to run the script without necessary rights.

      Is this a regularly recurring task in your environment?

    • #196475
      Participant
      Topics: 3
      Replies: 11
      Points: 55
      Rank: Member

      Hi Olaf . I’m only a student that trying to learn powershell & networking 🙂

      I’ ve already input Admin user and psw , but it starts the script an then close it

    • #196478
      Participant
      Topics: 5
      Replies: 2411
      Points: 6,193
      Helping Hand
      Rank: Community MVP

      I’m only a student that trying to learn powershell & networking 🙂

      So you might do a little step back, take a little time and start with learning the very basics of Powershell from scratch. Otherwise it will be hard or sometimes nearly impossible for you to understand the help you get in forums like this or in StackOverflow.
      One easy way to get started is to watch the free video course with Jeffrey Snover on Channel 9: “Microsoft Channel 9 – Getting Started with Microsoft PowerShell 3.0

      A complex technology like Powershell cannot be learned properly by asking arbitrary questions in forums or by copying code snippets from the internt.

      I’ ve already input Admin user and psw , but it starts the script an then close it

      I’m not a database guy so I don’t know about the correct options for MariaDB but if you start your Powershell console as admin the following code installs MariaDB with the given options:

      $StartProcessProps = @{
          Filepath = 'msiexec.exe'
          ArgumentList = @(
              '/i',
              'fullpath to the install file\mariadb-10.4.11-winx64.msi',
              'INSTALLDIR=c:\SQL',
              'DATADIR=c:\dbData',
              'PASSWORD=powershell',
              'SERVICENAME=MariaSQL',
              '/qn'
          )
          Wait         = $true
          NoNewWindow  = $true
      }
      Start-Process @StartProcessProps

      Of course you can change or add or remove options to make it suitable for your needs.

      Regardless of that: Please – before you ask a question in a forum spend a little effort to solve the problem yourself. Most of the time you’re not the first one with a given task and others probably solved it already.

      The technique I use here to make the code easier to read is called Spaltting. You can learn more about when you run

      Get-Help about_Splatting
      # or even more comfortable
      Get-Help about_Splatting -ShowWindow
    • #196490
      Participant
      Topics: 3
      Replies: 11
      Points: 55
      Rank: Member

      It was hard for me, but it’s working

      I saw many syntax errors and error messages didn’t help always

      Below is the code (not final)

      my previous errors: Every step took me some time.

      1) #Concatenation trough ‘+’ operator doesn’t works! It doesn’t even make sense if we use ‘@(….’     and    ‘@(‘  is mandatory here.
      `$arg1 =   "--datadir=" + $installDrive + $DB`
      `$arg2 =   "--service=DB"`
      `$arg3 =   "--password=acis"`
      `$allArgs = @($arg1,$arg2,$arg3)`
      2) ‘-Credential’ is different from ‘RunAs’  😐
      `$c = Get-Credential`
      `Start-Process cmd.exe -arg "/k C:\eclipse2019-12\Workspace\db\startMaria.bat" -Credential ($c)`
      3) if your run script.ps1 renember to set  -ExecutionPolicy Bypass 
      You can insert it in the batch file or within the script
      4) When you start service you need Admin rights, ok but I dont want start the first script as Admin
         so How Can I run an elevated script from a non-elevated ?
      `powershell.exe "Start-Process powershell C:\eclipse2019-12\Workspace\db\startMaria.bat -verb runAs"`
      5) I dont want another windows console
      `powershell.exe "Start-Process powershell -WindowStyle Hidden C:\eclipse2019-12\Workspace\db\startMaria.bat -verb runAs"`
      6) I dont want to use batch file. Run only the ps1 file
      `Start-Process powershell.exe -NoProfile -ExecutionPolicy Bypass -File `"C:\eclipse2019-12\Workspace\db\Start_MariaDB.ps1`"" -Verb RunAs  `
      7) I want to replace string with variable
      `$script = "C:\eclipse2019-12\Workspace\db\Start_MariaDB.ps1"`
      `Start-Process powershell.exe "-NoProfile -ExecutionPolicy Bypass -File $script" -Verb RunAs`     <------------- works!
      8 ) How Do I put inline  ‘-WorkingDirectory’ ?
      It still doesn’t work 😀
      Start_Maria.ps1
      `#Requires -RunAsAdministrator`
      `$installDrive               = "C:\DB"`
      `function set-MariaDbservice {`
      `Write-Host "New folder -> " $installDrive  -ForegroundColor Green  `
      `new-item $installDrive -itemtype directory | Out-Null`
      `  $arg1 =   "--datadir=C:\DB"`
      `  $arg2 =   "--service=DB"`
      `  $arg3 =   "--password=powershell"`
      `  $allArgs = @($arg1,$arg2,$arg3)`
      `  Start-Process  -FilePath "mysql_install_db.exe" -ArgumentList $allArgs -WorkingDirectory "C:\setup\mariadb-10.4.11-winx64\bin\" `
      `  $arg1 = "start"`
      `  $arg2 = "DB"  `
      `  $allArgs = @($arg1,$arg2)`
      `  Start-Process  -FilePath "sc" -ArgumentList $allArgs`
      `}`
      `set-MariaDbservice`
    • #196571
      Participant
      Topics: 3
      Replies: 11
      Points: 55
      Rank: Member

      It was hard for me, but it’s working

      I saw many syntax errors and error messages didn’t help always

      Below is the code (not final)

      my previous errors: Every step took me some time.

      1) ‘-Credential’ is different from ‘RunAs’  😐
      <sup>`$c = Get-Credential`</sup>
      <sup>`Start-Process cmd.exe -arg "/k C:\eclipse2019-12\Workspace\db\startMaria.bat" -Credential ($c)`</sup>

      2) if your run script.ps1 renember to set  -ExecutionPolicy Bypass 
      You can insert it in the batch file or within the script

      3) When you start service you need Admin rights, ok but I dont want start the first script as Admin
      so How Can I run an elevated script from a non-elevated ?
      `powershell.exe "Start-Process powershell C:\eclipse2019-12\Workspace\db\startMaria.bat -verb runAs"`

      4) I dont want another windows console
      `powershell.exe "Start-Process powershell -WindowStyle Hidden C:\eclipse2019-12\Workspace\db\startMaria.bat -verb runAs"`
      5) I dont want to use batch file. Run only the ps1 file
      `Start-Process powershell.exe -NoProfile -ExecutionPolicy Bypass -File `"C:\eclipse2019-12\Workspace\db\Start_MariaDB.ps1`"" -Verb RunAs  `
      6) I want to replace string with variable
      `$script = "C:\eclipse2019-12\Workspace\db\Start_MariaDB.ps1"`
      `Start-Process powershell.exe "-NoProfile -ExecutionPolicy Bypass -File $script" -Verb RunAs`     <------------- works!
      7 ) How Do I put inline  ‘-WorkingDirectory’ ?
      It still doesn’t work 😀

      Start_Maria.ps1
      `#Requires -RunAsAdministrator`
      `$installDrive               = "C:\DB"`
      `function set-MariaDbservice {`
      `Write-Host "New folder -> " $installDrive  -ForegroundColor Green  `
      `new-item $installDrive -itemtype directory | Out-Null`
      `  $arg1 =   "--datadir=C:\DB"`
      `  $arg2 =   "--service=DB"`
      `  $arg3 =   "--password=powershell"`
      `  $allArgs = @($arg1,$arg2,$arg3)`
      `  Start-Process  -FilePath "mysql_install_db.exe" -ArgumentList $allArgs -WorkingDirectory "C:\setup\mariadb-10.4.11-winx64\bin\" `
      `  $arg1 = "start"`
      `  $arg2 = "DB"  `
      `  $allArgs = @($arg1,$arg2)`
      `  Start-Process  -FilePath "sc" -ArgumentList $allArgs`
      `}`
      `set-MariaDbservice`

    • #196610
      Participant
      Topics: 5
      Replies: 2411
      Points: 6,193
      Helping Hand
      Rank: Community MVP

      I think you are overcomplicating the installation process. Assumed you started your Powershell console elevated the following snippet should be enough to install MariaDB server

      $Props = @{
          FilePath = 'msiexec.exe'
          ArgumentList = @(
              '/i',
              'fullpath\mariadb-10.4.11-winx64.msi'
              'INSTALLDIR=c:\SQL'
              'DATADIR=c:\dbData'
              'PASSWORD=powershell'
              'SERVICENAME=MariaSQL'
              '/qn'
          )
          Wait = $true
          NoNewWindow = $true
      }
      
      Start-Process @Props

      As I’m not a database guy I don’t know how to set up a database instance properly, but the installation works this way.

      The technique I’m using to make the code better readable is called splatting. You can read more about when you run in your Powershell Console:

      Get-Help about_Splatting
      # or even more comfortable
      Get-Help about_Splatting -ShowWindow
    • #196661
      Participant
      Topics: 13
      Replies: 1683
      Points: 2,849
      Helping Hand
      Rank: Community Hero
    • #196844
      Participant
      Topics: 3
      Replies: 11
      Points: 55
      Rank: Member

      Thank you both

Viewing 13 reply threads
  • The topic ‘Download and run MariaDB installer’ is closed to new replies.