MySQL HeatWave is the only fully managed MySQL database service that combines transactions, analytics, machine learning, and GenAI services, without ETL duplication. Also included is MySQL HeatWave Lakehouse, which allows users to query data in object storage, MySQL databases, or a combination of both. Users can deploy MySQL HeatWave–powered apps on a choice of public clouds: Oracle Cloud Infrastructure (OCI), Amazon Web Services (AWS), and Microsoft Azure.

We’re thrilled to announce a revolutionary leap for database developers, WebAssembly (Wasm) support now comes to MySQL Heatwave! For the first time, you can bring high-performance, portable code, compiled from Rust, C++, and many more languagesdirectly to your MySQL data, unlocking a new universe of speed, flexibility, and innovation.

Cloud-native, data-hungry applications demand more: faster analytics, richer data processing, less operational friction, all while staying flexible across tools and platforms. MySQL+Wasm is here to put all that power into your hands, with the same skills and code ecosystem you already know.

WebAssembly and MySQL
WebAssembly and MySQL

What is WebAssembly?

WebAssembly (Wasm) is a secure, compact, and blazing-fast binary instruction format. Originally born to speed up web apps across all major browsers, it enables code written in languages like Rust, C, and C++ to run anywhere, with near-native performance and strong sandboxing for safety. Today, Wasm’s magic is spreading far beyond the browser, powering plugins, edge devices, and now, the MySQL database itself!

Over the years, JavaScript has become the backbone of cloud and web innovation, and MySQL’s integration with JavaScript has made stored logic approachable for millions of developers. By embracing WebAssembly, MySQL lets you combine familiar JavaScript with Wasm modules, bringing your favorite libraries, algorithms, and code investments right into the database.

  • Reuse code: Harness the power of existing open-source Wasm libraries or migrate code you trust.
  • Leverage your skillset: Write database-side logic in the languages your team already loves.

How Does WebAssembly Supercharge MySQL?

  • Fast, Secure Performance: Run compiled code at near-native speed, securely sandboxed using GraalVM.
  • Language FlexibilityTap into Rust, C++, C#, Go, and more, right in stored procedures.
  • Ecosystem at Your Fingertips: Import open-source Wasm libraries instead of reinventing wheels.
  • Empower Full-stack Developers: Blend backend and database skills, no SQL-only barriers.
  • Accelerate Innovation: Stay nimble by integrating trusted code or new modules as your data evolves.
  • Reduced Complexity/Cost: Ditch separate middleware for specialized logic; lower latency and less network overhead.
  • Portability & Migration: Write portable modules once, migrate them from client to MySQL server at your own pace.

Real-World Use Cases: Redefining What’s Possible

You can now code directly against your data, the possibilities are limitless! Below is just a short list of use cases 

Data Processing & Transformation

  • Algorithms: Deploy custom Tokenization, Hashing, Encoding and Compression algorithms right inside the database.
  • Custom Data Cleaning: Run high-speed, tuned routines for standardizing or verifying data quality.
  • Domain-Specific Engines: Embed sophisticated engines (financial pricing, geospatial logic) as in-database functions.

Analytics & Machine Learning

  • Advanced Aggregations: Build custom analytic or similarity search functions well beyond standard SQL capabilities.
  • Scientific Computation: Integrate advanced math/statistics libraries for complex queries.
  • Scoring & Prediction: Run lightweight ML scoring or rules directly as stored logic.

Security & Cryptography

  • Custom Encryption/Decryption: Apply modern cryptographic routines within MySQL.

  • Digital Signatures: Verify or create digital signatures for data authenticity.

Media & Content Processing

  • Image Manipulation: Extract metadata, create thumbnails or convert formats, inline with SQL queries.

  • Dynamic Document Generation: Create PDFs or Excel spreadsheets from live data in a snap.

Compliance & Auditing

  • In-Place Data Masking: Anonymize or scrub sensitive fields before export.

  • Auditable Data Logic: Centralize business-critical logic for easier verification and compliance.

  • Inline Validation: Accept only “clean,” validated data by running Wasm-powered checks at commit time.

Getting Started: Run Your First WebAssembly in MySQL

Curious how easy it is? Here’s a lightning-fast walkthrough: 

Before starting, lets check to see if the feature is available. The feature is available in version 9.4 and above in MySQL HeatWave cloud service and also in Enterprise edition where the mle component requires installation

mysql> SHOW STATUS LIKE 'mle_languages%'; 
    +-------------------------+-------------------------+
    | Variable_name           | Value                   | 
    +-------------------------+-------------------------+ 
    | mle_languages_supported | JavaScript, WebAssembly | 
    +-------------------------+-------------------------+ 
    1 row in set (0.001 sec)

 

Step 1:

First, you need a WebAssembly binary, you can pick one from an already existing open source project. Here we build a simple utility library for prime numbers using C language. Below is the content of the prime.c file.

#include <stdbool.h> 
    #include <stdint.h> 
    
    // Returns 1 if n is prime, 0 otherwise int 
    is_prime(uint32_t n) {
      if (n < 2u) 
        return 0; 
      if (n == 2u) 
        return 1; 
      if ((n & 1u) == 0u) 
        return 0; 
      for (uint32_t i = 3u; i <= n / i; i += 2u) {
       if (n % i == 0u) 
         return 0; } return 1; 
      }
    
    // Returns the first prime >= n 
    uint32_t next_prime(uint32_t n) {
      if (n <= 2u)
        return 2u; 
      if ((n & 1u) == 0u) 
        n++; 
      for (;;) { 
        if (is_prime(n)) 
          return n; 
        n += 2u; 
      } 
    }

We then use the Emscripten compiler toolchain, to build the WebAssembly standalone binary. 

emcc prime.c -O3 \ 
      -s STANDALONE_WASM=1 \
      -Wl,--no-entry \ 
      -Wl,--export=is_prime \ 
      -Wl,--export=next_prime \ 
      -o prime.wasm

Step 2

Load Wasm into MySQL: Once the prime.wasm binary is built, we use the binary content to generate the CREATE LIBRARY DDL statement, that includes the binary as base64 encoded string.

CREATE LIBRARY prime_wasm LANGUAGE WASM AS $$ AGFzbQEAAAABDgNgAX8Bf2ABfwBgAAF/AwUEAAABAgQFAXABAQEFBgEBggKCAgYIAX8BQYCIBAsHeQYGbWVtb3J5AgAIaXNfcHJpbWUAAApuZXh0X3ByaW1lAAEZX19pbmRpcmVjdF9mdW5jdGlvbl90YWJsZQEAGV9lbXNjcmlwdGVuX3N0YWNrX3Jlc3RvcmUAAhxlbXNjcmlwdGVuX3N0YWNrX2dldF9jdXJyZW50AAMKxAEEUQECfwJAAkAgAEECSQ0AQQEhAiAAQQJGDQEgAEEBcUUNACAAQQlJDQFBAyEBA0AgACABcEUNASABQQJqIgEgACABbk0NAAsMAQtBACECCyACC2QBAX8Cf0ECIABBA0kNABogAEEBciEAA0ACQAJAIABBAkkNAEECIABBAkYNAxpBAyEBIABBCUkNAQNAIAAgAXBFDQEgAUECaiIBIAAgAW5NDQALDAELIABBAmohAAwBCwsgAAsLBgAgACQACwQAIwAL 
    $$;

Manually encoding the Wasm binary into base64 can be a hassle, instead the MySQL Shell VSCode Extension can do this for you by loading the Wasm file from the client’s local file system.

Encoding the Wasm library using the MySQL Shell Extension for VS Code - 1
Encoding the Wasm library using the MySQL Shell Extension for VS Code – 1
Encoding the Wasm library using the MySQL Shell Extension for VS Code - 2
Encoding the Wasm library using the MySQL Shell Extension for VS Code – 1

Step 3

Import Wasm Library into stored programs and execute Below we use a simple JavaScript function to expose one of the methods present in the Wasm binary and execute it using a SELECT statement.

CREATE FUNCTION is_prime(arg1 INTEGER) RETURNS BOOLEAN 
    USING (prime_wasm AS lib) 
    LANGUAGE JAVASCRIPT AS $$ 
       return lib.is_prime(arg1); $$; 
    
    mysql> SELECT is_prime(319), is_prime(317); 
    +---------------+---------------+ 
    | is_prime(319) | is_prime(317) | 
    +---------------+---------------+ 
    | 0             |             1 | 
    +---------------+---------------+ 
    1 row in set (0.010 sec)

Above we use simple example for creating standalone Wasm. Complex real world example require more sophisticated ways to generate the Wasm binary that can be inlined within JavaScript to deal with complex types and database environment. but that is another blog article so stay tuned!

Summary: Unlock the Future of Data Apps, Today

In addition to its innovative capabilities,, the new WebAssembly feature in MySQL inherits all the robust security benefits established by the existing LIBRARY feature in MySQL, as described in our previous blog. This includes strict privilege management and comprehensive sandboxing for loaded libraries. WebAssembly execution also leverages the GraalVM sandbox, which enforces memory safety and strictly isolates code, regardless of the original programming language used to create the WASM binary. WebAssembly modules have no direct access to system resources such as disk I/O, network communications, or system calls, providing strong protection for your database environment.

Lets summarize the key takeaways from this feature.  With WebAssembly support in MySQL, you can:

  • Harness opensource projects and your existing code libraries and developer skillset,
  • Create richer, faster, and more secure user experiences,
  • And accelerate innovation, without rewriting your stack.
  • Reduce data movement and complexity,

Learn more!

Try it out in MySQL 9.4!