Skip to content


Switch branches/tags


Build Status Code Coverage Release License

Async MySQL client built with Amp.

amp/mysql is an asynchronous MySQL client built on the Amp concurrency framework. The library exposes a Promise-based API to dynamically query multiple MySQL connections concurrently. The client transparently distributes these queries across a scalable pool of available connections and does so using 100% userland PHP; there are no external extension dependencies (e.g. ext/mysqli, ext/pdo, etc).


  • Asynchronous API exposing full single-threaded concurrency
  • Transparent connection pooling to overcome MySQL's fundamentally synchronous connection protocol
  • MySQL transfer encoding support (gzip, TLS encryption)
  • Support for all MySQL commands

† As documented in official Mysql Internals Manual

Project Goals

  • Expose a non-blocking API for issuing multiple MySQL queries in parallel
  • Support the full MySQL protocol and all available commands asynchronously


This package can be installed as a Composer dependency.

composer require amphp/mysql


Documentation & Examples

More extensive code examples reside in the examples directory.

Amp\Loop::run(function() {
    $config = Amp\Mysql\ConnectionConfig::fromString(
        "host= user=username password=password db=test"
    /** @var \Amp\Mysql\Pool $pool */
    $pool = Amp\Mysql\pool($config);
    /** @var \Amp\Mysql\Statement $statement */
    $statement = yield $pool->prepare("SELECT * FROM table_name WHERE id = :id");
    /** @var \Amp\Mysql\ResultSet $result */
    $result = yield $statement->execute(['id' => 1337]);
    while (yield $result->advance()) {
        $row = $result->getCurrent();
        // $row is an associative array of column values. e.g.: $row['column_name']


amphp/mysql follows the semver semantic versioning specification like all other amphp packages.


If you discover any security related issues, please email instead of using the issue tracker.


The MIT License (MIT). Please see LICENSE for more information.