鈴木  治

鈴木 治

1656739140

如何在 Laravel 8 中以 CSV 和 Excel 格式導出 MySQL 數據庫數據

在 Laravel 中,您不必編寫長代碼來導出數據,已經有一個可用的包 - Laravel Excel。

它允許以各種格式導出數據,例如 XLSX、CSV、XLS、HTML 等。

在本教程中,我將展示如何使用 Laravel 8 中的 Laravel Excel 包以 CSV 和 Excel 格式導出 MySQL 數據庫數據。


1.安裝包

要求 -

  • PHP: ^7.2\|^8.0
  • 拉拉維爾: ^5.8
  • Php電子表格: ^1.21
  • psr/簡單緩存: ^1.0
  • php_zip 啟用PHP 擴展 
  • php_xml 啟用PHP 擴展 
  • php_gd2 啟用PHP 擴展 
  • php_iconv 啟用PHP 擴展 
  • php_simplexml 啟用PHP 擴展 
  • php_xmlreader 啟用PHP 擴展 
  • php_zlib 啟用PHP 擴展 

使用 composer 安裝包——

composer require maatwebsite/excel

如果您在執行上述命令時遇到錯誤,請執行以下命令 -

composer require psr/simple-cache:^1.0 maatwebsite/excel

之後再次執行 -

composer require maatwebsite/excel

2.更新app.php

  • 打開 config/app.php 文件。
  • 將以下內容添加Maatwebsite\Excel\ExcelServiceProvider::class 到 'providers' –
'providers' => [
      ....
      ....
      ....  
      Maatwebsite\Excel\ExcelServiceProvider::class
];
  • 將以下內容添加 'Excel' => Maatwebsite\Excel\Facades\Excel::class 到 'aliases' –
'aliases' => [
     .... 
     .... 
     .... 
     'Excel' => Maatwebsite\Excel\Facades\Excel::class
];

3.發布包

運行命令——

php artisan vendor:publish --provider="Maatwebsite\Excel\ExcelServiceProvider" --tag=config

這將excel.phpconfig/.


4. 數據庫配置

打開.env文件。

指定主機、數據庫名稱、用戶名和密碼。

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=tutorial
DB_USERNAME=root
DB_PASSWORD=

5. 創建表

  • Employees使用遷移創建一個新表並添加一些記錄。
php artisan make:migration create_employees_table
  • database/migrations/現在,從項目根目錄導航到文件夾。
  • 找到一個以 結尾的 PHP 文件create_employees_table並打開它。
  • 在方法中定義表結構up()
public function up()
{
    Schema::create('employees', function (Blueprint $table) {
        $table->id();
        $table->string('username');
        $table->string('name');
        $table->string('email');
        $table->smallInteger('age');
        $table->timestamps();
    });
}
  • 運行遷移 -
php artisan migrate
  • 表已創建並在其中添加一些記錄。

6. 型號

  • 創建Employees模型。
php artisan make:model Employees
  • 打開 app/Models/Employees.php 文件。
  • 使用該屬性指定可批量分配的模型屬性——用戶名、姓名、電子郵件和年齡$fillable

完成的代碼

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Employees extends Model
{
    use HasFactory;

    protected $fillable = [
       'username','name','email','age'
    ];
}

7. 創建導出類

我創建 2 個導出類只是為了舉例 -

1.EmployeesExport 類——

php artisan make:export EmployeesExport --model=Employees
  • 打開 app/Exports/EmployeesExport.php 文件。

類有 2 種方法——

  • collection() –加載導出數據。在這裡,您可以——
    • 返回所有記錄。
    • 返回特定列或修改我在下一個導出類中所做的返迴響應。
  • headings() –指定標題行。

注意 –如果您不想添加標題行,請刪除 headings() 方法。

完成的代碼

<?php

namespace App\Exports;

use App\Models\Employees;
use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\WithHeadings;

class EmployeesExport implements FromCollection, WithHeadings
{

    /**
    * @return \Illuminate\Support\Collection
    */
    public function collection()
    {
        ## 1. Export all data
        // return Employees::all();

        ## 2. Export specific columns
        return Employees::select('id','username','name')->get();

    }

    public function headings(): array
    {
        return [
          '#',
          'Username',
          'Name'
        ];
    }
}

2.EmployeesByAgeExport 類——

php artisan make:export EmployeesByAgeExport --model=Employees
  • 打開 app/Exports/EmployeesByAgeExport.php 文件。
  • 在這個類中,我添加__construct()了允許在創建類實例時發送參數並使用它來檢索數據。
  • 初始化$resultArray 後傳入$result返回collect()-return collect($result);
  • 在方法中提及標題行名稱heading()

完成的代碼

<?php

namespace App\Exports;

use App\Models\Employees;
use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\WithHeadings;

class EmployeesByAgeExport implements FromCollection, WithHeadings
{
    private $agegreaterthan;

    public function __construct($age=0) 
    {
        $this->agegreaterthan = $age;
    }

    /**
    * @return \Illuminate\Support\Collection
    */
    public function collection()
    {
        ## 3. Conditional export and customize result
        $records = Employees::select('*')->where('age','>',$this->agegreaterthan)->get();

        $result = array();
        foreach($records as $record){
           $result[] = array(
              'id'=>$record->id,
              'username' => $record->username,
              'name' => $record->name,
              'email' => $record->email,
              'age' => $record->age,
              'status' => 1 // Custom data
           );
        }

        return collect($result);
    }

    public function headings(): array
    {
       return [
         '#',
         'Username',
         'Name',
         'Email',
         'Age',
         'Status'
       ];
    }
}

8. 路線

  • 打開 routes/web.php 文件。
  • 定義 4 條路線 –
    • / - 加載索引視圖。
    • employees/exportcsv –以 CSV 格式導出數據。
    • employees/exportexcel –以 Excel 格式導出數據。
    • employees/exportbyagecsv –按年齡導出數據的 POST 路由。

完成的代碼

<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\EmployeesController;

Route::get('/', [EmployeesController::class, 'index'])->name('home'); 
Route::get('employees/exportcsv', [EmployeesController::class, 'exportCSV'])->name('employees.exportcsv');
Route::get('employees/exportexcel', [EmployeesController::class, 'exportExcel'])->name('employees.exportexcel');
Route::post('employees/exportbyagecsv', [EmployeesController::class, 'exportByAgeCSV'])->name('employees.exportbyagecsv');

9.控制器

  • 創建 EmployeesController 控制器。
php artisan make:controller EmployeesController
  • 打開 app/Http/Controllers/EmployeesController.php 文件。
  • 導入和。EmployeesExportEmployeesByAgeExportExcel
  • 創建 4 種方法 –
    • index() -加載index視圖。
    • exportCSV() – 導出數據調用Excel::download()

它需要 2 個參數——

  1. 類實例。
  2. 帶擴展名的文件名。
$file_name = 'employees_'.date('Y_m_d_H_i_s').'.csv'; 
return Excel::download(new EmployeesExport, $file_name);
  • exportExcel() –使用與上述相同的代碼並將文件擴展名更改為 .xlsx。
  • exportByAgeCSV() –讀取 POST 年齡值並將其與EmployeesByAgeExport($age)實例一起傳遞。
$file_name = 'employees_'.date('Y_m_d_H_i_s').'.csv'; 
return Excel::download(new EmployeesByAgeExport($age), $file_name);

完成的代碼

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Exports\EmployeesExport;
use App\Exports\EmployeesByAgeExport;
use Excel;

class EmployeesController extends Controller
{
    public function index(){
       return view('index');
    }

    // CSV Export
    public function exportCSV(){
       $file_name = 'employees_'.date('Y_m_d_H_i_s').'.csv';
       return Excel::download(new EmployeesExport, $file_name);
    }

    // Excel Export
    public function exportExcel(){
       $file_name = 'employees_'.date('Y_m_d_H_i_s').'.xlsx';
       return Excel::download(new EmployeesExport, $file_name);
    }

    // Conditional Export (csv)
    public function exportByAgeCSV(Request $request){

       $age = $request->age;

       $file_name = 'employees_'.date('Y_m_d_H_i_s').'.csv';
       return Excel::download(new EmployeesByAgeExport($age), $file_name);
    }
}

10. 查看

index.blade.php 在 文件夾中創建 文件resources/views/ 。

創建 2 個錨元素 -

  1. 設置href{{ route('employees.exportcsv') }}CSV 導出。
  2. 設置href{{ route('employees.exportexcel') }}Excel 導出。

創建一個<form method='post' action="{{ route('employees.exportbyagecsv') }}">. 添加輸入元素以輸入年齡和提交按鈕。

完成的代碼

<!DOCTYPE html>
<html>
<head>
   <meta charset="utf-8">
   <meta name="viewport" content="width=device-width, initial-scale=1"> 
   <title>How to Export data to CSV & Excel format in Laravel 8</title>

   <!-- CSS -->
   <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.0-beta1/dist/css/bootstrap.min.css" rel="stylesheet" >
</head>
<body>

   <div class="container mt-5">

      <a class="btn btn-primary" href="{{ route('employees.exportcsv') }}">CSV Export</a> &nbsp;&nbsp;
      <a class="btn btn-primary" href="{{ route('employees.exportexcel') }}">Excel Export</a><br><br>

      <form method='post' action="{{ route('employees.exportbyagecsv') }}">
         @csrf
         <div class="mb-3">
            <label for="age" class="form-label">Age</label>
            <input type="number" class="form-control" id="age" name="age" value="0">
         </div>

         <button type="submit" class="btn btn-success">Export</button>
      </form>
   </div>

</body>
</html>

11. 演示

查看演示


12. 結論

在 Export 類中使用構造函數來處理傳遞的參數並使用它來獲取數據。

在本教程中,我只提到了 2 種導出格式——CSV 和 Excel,但還有更多可用的格式。

來源:https ://makitweb.com

#php #laravel #mysql 

What is GEEK

Buddha Community

如何在 Laravel 8 中以 CSV 和 Excel 格式導出 MySQL 數據庫數據

Laravel 8 Import Export CSV/EXCEL File Example

In this post i will show you Laravel 8 Import Export CSV/EXCEL File Example. We will simple create import data to xls, csv file and also we will import data to database using csv file in laravel 8 application.

Using this example we can easily import-export and download the csv & excel file from the database using the maatwebsite/excel composer package. maatwebsite/excel provide easy way to import and export csv file in laravel 8 using database model.

Laravel 8 Import Export CSV/EXCEL File Example

https://websolutionstuff.com/post/laravel-8-import-export-csv-excel-file-example

#laravel 8 import export csv/excel file example #laravel 8 #import #export #csv/excel #import and export csv file in laravel 8

I am Developer

1617089618

Laravel 8 Tutorial for Beginners

Hello everyone! I just updated this tutorial for Laravel 8. In this tutorial, we’ll go through the basics of the Laravel framework by building a simple blogging system. Note that this tutorial is only for beginners who are interested in web development but don’t know where to start. Check it out if you are interested: Laravel Tutorial For Beginners

Laravel is a very powerful framework that follows the MVC structure. It is designed for web developers who need a simple, elegant yet powerful toolkit to build a fully-featured website.

Recommended:-Laravel Try Catch

#laravel 8 tutorial #laravel 8 tutorial crud #laravel 8 tutorial point #laravel 8 auth tutorial #laravel 8 project example #laravel 8 tutorial for beginners

I am Developer

1599536794

Laravel 8 New Features | Release Notes - Tuts Make

In this post, i will show you what’s new in laravel 8 version.

#What’s new in Laravel 8?

  • 1 - Change Path Of Default Models Directory
  • 2 - Removed Controllers Namespace Prefix
  • 3 - Enhancements on php artisan serve
  • 4 - Enhanced Rate Limiting
  • 5 - Enhanced on Route Caching
  • 6 - Update on Pagination Design
  • 8 - Dynamic Blade Componenets
  • 7 - Update Syntax for Closure Based Event Listeners
  • 8 - Queueable Model Event Listeners
  • 9 - Maintenance mode: secret access
  • 10 - Maintenance mode: pre-rendered page
  • 11 - Queued job batching
  • 12 - Queue backoff()
  • 13 - Laravel Factory

https://www.tutsmake.com/laravel-8-new-features-release-notes/

#laravel 8 features #laravel 8 release date #laravel 8 tutorial #news - laravel 8 new features #what's new in laravel 8 #laravel 8 release notes

鈴木  治

鈴木 治

1656739140

如何在 Laravel 8 中以 CSV 和 Excel 格式導出 MySQL 數據庫數據

在 Laravel 中,您不必編寫長代碼來導出數據,已經有一個可用的包 - Laravel Excel。

它允許以各種格式導出數據,例如 XLSX、CSV、XLS、HTML 等。

在本教程中,我將展示如何使用 Laravel 8 中的 Laravel Excel 包以 CSV 和 Excel 格式導出 MySQL 數據庫數據。


1.安裝包

要求 -

  • PHP: ^7.2\|^8.0
  • 拉拉維爾: ^5.8
  • Php電子表格: ^1.21
  • psr/簡單緩存: ^1.0
  • php_zip 啟用PHP 擴展 
  • php_xml 啟用PHP 擴展 
  • php_gd2 啟用PHP 擴展 
  • php_iconv 啟用PHP 擴展 
  • php_simplexml 啟用PHP 擴展 
  • php_xmlreader 啟用PHP 擴展 
  • php_zlib 啟用PHP 擴展 

使用 composer 安裝包——

composer require maatwebsite/excel

如果您在執行上述命令時遇到錯誤,請執行以下命令 -

composer require psr/simple-cache:^1.0 maatwebsite/excel

之後再次執行 -

composer require maatwebsite/excel

2.更新app.php

  • 打開 config/app.php 文件。
  • 將以下內容添加Maatwebsite\Excel\ExcelServiceProvider::class 到 'providers' –
'providers' => [
      ....
      ....
      ....  
      Maatwebsite\Excel\ExcelServiceProvider::class
];
  • 將以下內容添加 'Excel' => Maatwebsite\Excel\Facades\Excel::class 到 'aliases' –
'aliases' => [
     .... 
     .... 
     .... 
     'Excel' => Maatwebsite\Excel\Facades\Excel::class
];

3.發布包

運行命令——

php artisan vendor:publish --provider="Maatwebsite\Excel\ExcelServiceProvider" --tag=config

這將excel.phpconfig/.


4. 數據庫配置

打開.env文件。

指定主機、數據庫名稱、用戶名和密碼。

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=tutorial
DB_USERNAME=root
DB_PASSWORD=

5. 創建表

  • Employees使用遷移創建一個新表並添加一些記錄。
php artisan make:migration create_employees_table
  • database/migrations/現在,從項目根目錄導航到文件夾。
  • 找到一個以 結尾的 PHP 文件create_employees_table並打開它。
  • 在方法中定義表結構up()
public function up()
{
    Schema::create('employees', function (Blueprint $table) {
        $table->id();
        $table->string('username');
        $table->string('name');
        $table->string('email');
        $table->smallInteger('age');
        $table->timestamps();
    });
}
  • 運行遷移 -
php artisan migrate
  • 表已創建並在其中添加一些記錄。

6. 型號

  • 創建Employees模型。
php artisan make:model Employees
  • 打開 app/Models/Employees.php 文件。
  • 使用該屬性指定可批量分配的模型屬性——用戶名、姓名、電子郵件和年齡$fillable

完成的代碼

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Employees extends Model
{
    use HasFactory;

    protected $fillable = [
       'username','name','email','age'
    ];
}

7. 創建導出類

我創建 2 個導出類只是為了舉例 -

1.EmployeesExport 類——

php artisan make:export EmployeesExport --model=Employees
  • 打開 app/Exports/EmployeesExport.php 文件。

類有 2 種方法——

  • collection() –加載導出數據。在這裡,您可以——
    • 返回所有記錄。
    • 返回特定列或修改我在下一個導出類中所做的返迴響應。
  • headings() –指定標題行。

注意 –如果您不想添加標題行,請刪除 headings() 方法。

完成的代碼

<?php

namespace App\Exports;

use App\Models\Employees;
use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\WithHeadings;

class EmployeesExport implements FromCollection, WithHeadings
{

    /**
    * @return \Illuminate\Support\Collection
    */
    public function collection()
    {
        ## 1. Export all data
        // return Employees::all();

        ## 2. Export specific columns
        return Employees::select('id','username','name')->get();

    }

    public function headings(): array
    {
        return [
          '#',
          'Username',
          'Name'
        ];
    }
}

2.EmployeesByAgeExport 類——

php artisan make:export EmployeesByAgeExport --model=Employees
  • 打開 app/Exports/EmployeesByAgeExport.php 文件。
  • 在這個類中,我添加__construct()了允許在創建類實例時發送參數並使用它來檢索數據。
  • 初始化$resultArray 後傳入$result返回collect()-return collect($result);
  • 在方法中提及標題行名稱heading()

完成的代碼

<?php

namespace App\Exports;

use App\Models\Employees;
use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\WithHeadings;

class EmployeesByAgeExport implements FromCollection, WithHeadings
{
    private $agegreaterthan;

    public function __construct($age=0) 
    {
        $this->agegreaterthan = $age;
    }

    /**
    * @return \Illuminate\Support\Collection
    */
    public function collection()
    {
        ## 3. Conditional export and customize result
        $records = Employees::select('*')->where('age','>',$this->agegreaterthan)->get();

        $result = array();
        foreach($records as $record){
           $result[] = array(
              'id'=>$record->id,
              'username' => $record->username,
              'name' => $record->name,
              'email' => $record->email,
              'age' => $record->age,
              'status' => 1 // Custom data
           );
        }

        return collect($result);
    }

    public function headings(): array
    {
       return [
         '#',
         'Username',
         'Name',
         'Email',
         'Age',
         'Status'
       ];
    }
}

8. 路線

  • 打開 routes/web.php 文件。
  • 定義 4 條路線 –
    • / - 加載索引視圖。
    • employees/exportcsv –以 CSV 格式導出數據。
    • employees/exportexcel –以 Excel 格式導出數據。
    • employees/exportbyagecsv –按年齡導出數據的 POST 路由。

完成的代碼

<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\EmployeesController;

Route::get('/', [EmployeesController::class, 'index'])->name('home'); 
Route::get('employees/exportcsv', [EmployeesController::class, 'exportCSV'])->name('employees.exportcsv');
Route::get('employees/exportexcel', [EmployeesController::class, 'exportExcel'])->name('employees.exportexcel');
Route::post('employees/exportbyagecsv', [EmployeesController::class, 'exportByAgeCSV'])->name('employees.exportbyagecsv');

9.控制器

  • 創建 EmployeesController 控制器。
php artisan make:controller EmployeesController
  • 打開 app/Http/Controllers/EmployeesController.php 文件。
  • 導入和。EmployeesExportEmployeesByAgeExportExcel
  • 創建 4 種方法 –
    • index() -加載index視圖。
    • exportCSV() – 導出數據調用Excel::download()

它需要 2 個參數——

  1. 類實例。
  2. 帶擴展名的文件名。
$file_name = 'employees_'.date('Y_m_d_H_i_s').'.csv'; 
return Excel::download(new EmployeesExport, $file_name);
  • exportExcel() –使用與上述相同的代碼並將文件擴展名更改為 .xlsx。
  • exportByAgeCSV() –讀取 POST 年齡值並將其與EmployeesByAgeExport($age)實例一起傳遞。
$file_name = 'employees_'.date('Y_m_d_H_i_s').'.csv'; 
return Excel::download(new EmployeesByAgeExport($age), $file_name);

完成的代碼

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Exports\EmployeesExport;
use App\Exports\EmployeesByAgeExport;
use Excel;

class EmployeesController extends Controller
{
    public function index(){
       return view('index');
    }

    // CSV Export
    public function exportCSV(){
       $file_name = 'employees_'.date('Y_m_d_H_i_s').'.csv';
       return Excel::download(new EmployeesExport, $file_name);
    }

    // Excel Export
    public function exportExcel(){
       $file_name = 'employees_'.date('Y_m_d_H_i_s').'.xlsx';
       return Excel::download(new EmployeesExport, $file_name);
    }

    // Conditional Export (csv)
    public function exportByAgeCSV(Request $request){

       $age = $request->age;

       $file_name = 'employees_'.date('Y_m_d_H_i_s').'.csv';
       return Excel::download(new EmployeesByAgeExport($age), $file_name);
    }
}

10. 查看

index.blade.php 在 文件夾中創建 文件resources/views/ 。

創建 2 個錨元素 -

  1. 設置href{{ route('employees.exportcsv') }}CSV 導出。
  2. 設置href{{ route('employees.exportexcel') }}Excel 導出。

創建一個<form method='post' action="{{ route('employees.exportbyagecsv') }}">. 添加輸入元素以輸入年齡和提交按鈕。

完成的代碼

<!DOCTYPE html>
<html>
<head>
   <meta charset="utf-8">
   <meta name="viewport" content="width=device-width, initial-scale=1"> 
   <title>How to Export data to CSV & Excel format in Laravel 8</title>

   <!-- CSS -->
   <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.0-beta1/dist/css/bootstrap.min.css" rel="stylesheet" >
</head>
<body>

   <div class="container mt-5">

      <a class="btn btn-primary" href="{{ route('employees.exportcsv') }}">CSV Export</a> &nbsp;&nbsp;
      <a class="btn btn-primary" href="{{ route('employees.exportexcel') }}">Excel Export</a><br><br>

      <form method='post' action="{{ route('employees.exportbyagecsv') }}">
         @csrf
         <div class="mb-3">
            <label for="age" class="form-label">Age</label>
            <input type="number" class="form-control" id="age" name="age" value="0">
         </div>

         <button type="submit" class="btn btn-success">Export</button>
      </form>
   </div>

</body>
</html>

11. 演示

查看演示


12. 結論

在 Export 類中使用構造函數來處理傳遞的參數並使用它來獲取數據。

在本教程中,我只提到了 2 種導出格式——CSV 和 Excel,但還有更多可用的格式。

來源:https ://makitweb.com

#php #laravel #mysql 

Joe  Hoppe

Joe Hoppe

1595905879

Best MySQL DigitalOcean Performance – ScaleGrid vs. DigitalOcean Managed Databases

HTML to Markdown

MySQL is the all-time number one open source database in the world, and a staple in RDBMS space. DigitalOcean is quickly building its reputation as the developers cloud by providing an affordable, flexible and easy to use cloud platform for developers to work with. MySQL on DigitalOcean is a natural fit, but what’s the best way to deploy your cloud database? In this post, we are going to compare the top two providers, DigitalOcean Managed Databases for MySQL vs. ScaleGrid MySQL hosting on DigitalOcean.

At a glance – TLDR
ScaleGrid Blog - At a glance overview - 1st pointCompare Throughput
ScaleGrid averages almost 40% higher throughput over DigitalOcean for MySQL, with up to 46% higher throughput in write-intensive workloads. Read now

ScaleGrid Blog - At a glance overview - 2nd pointCompare Latency
On average, ScaleGrid achieves almost 30% lower latency over DigitalOcean for the same deployment configurations. Read now

ScaleGrid Blog - At a glance overview - 3rd pointCompare Pricing
ScaleGrid provides 30% more storage on average vs. DigitalOcean for MySQL at the same affordable price. Read now

MySQL DigitalOcean Performance Benchmark
In this benchmark, we compare equivalent plan sizes between ScaleGrid MySQL on DigitalOcean and DigitalOcean Managed Databases for MySQL. We are going to use a common, popular plan size using the below configurations for this performance benchmark:

Comparison Overview
ScaleGridDigitalOceanInstance TypeMedium: 4 vCPUsMedium: 4 vCPUsMySQL Version8.0.208.0.20RAM8GB8GBSSD140GB115GBDeployment TypeStandaloneStandaloneRegionSF03SF03SupportIncludedBusiness-level support included with account sizes over $500/monthMonthly Price$120$120

As you can see above, ScaleGrid and DigitalOcean offer the same plan configurations across this plan size, apart from SSD where ScaleGrid provides over 20% more storage for the same price.

To ensure the most accurate results in our performance tests, we run the benchmark four times for each comparison to find the average performance across throughput and latency over read-intensive workloads, balanced workloads, and write-intensive workloads.

Throughput
In this benchmark, we measure MySQL throughput in terms of queries per second (QPS) to measure our query efficiency. To quickly summarize the results, we display read-intensive, write-intensive and balanced workload averages below for 150 threads for ScaleGrid vs. DigitalOcean MySQL:

ScaleGrid MySQL vs DigitalOcean Managed Databases - Throughput Performance Graph

For the common 150 thread comparison, ScaleGrid averages almost 40% higher throughput over DigitalOcean for MySQL, with up to 46% higher throughput in write-intensive workloads.

#cloud #database #developer #digital ocean #mysql #performance #scalegrid #95th percentile latency #balanced workloads #developers cloud #digitalocean droplet #digitalocean managed databases #digitalocean performance #digitalocean pricing #higher throughput #latency benchmark #lower latency #mysql benchmark setup #mysql client threads #mysql configuration #mysql digitalocean #mysql latency #mysql on digitalocean #mysql throughput #performance benchmark #queries per second #read-intensive #scalegrid mysql #scalegrid vs. digitalocean #throughput benchmark #write-intensive