cube-js/cube · error · Error

MySQL can not work with table names longer than 64 symbols.

Error message

MySQL can not work with table names longer than 64 symbols. Consider using the 'sqlAlias' attribute in your cube definition for ${quotedTableName}.

What it means

MySQL limits table (and identifier) names to 64 characters. MySqlDriver.createTable pre-checks the quoted table name length and refuses to create pre-aggregation/temp tables that exceed it, pointing the user at the `sqlAlias` cube attribute as the remedy.

Source

Thrown at packages/cubejs-mysql-driver/src/MySqlDriver.ts:285

    promise.cancel = () => cancelObj.cancel();
    return promise;
  }

  public async testConnection() {
    // eslint-disable-next-line no-underscore-dangle
    const conn: MySQLConnection = await (<any> this.pool)._factory.create();

    try {
      return await conn.execute('SELECT 1');
    } finally {
      // eslint-disable-next-line no-underscore-dangle
      await (<any> this.pool)._factory.destroy(conn);
    }
  }

  public async createTable(quotedTableName: string, columns: TableColumn[]): Promise<void> {
    if (quotedTableName.length > 64) {
      throw new Error('MySQL can not work with table names longer than 64 symbols. ' +
        `Consider using the 'sqlAlias' attribute in your cube definition for ${quotedTableName}.`);
    }
    return super.createTable(quotedTableName, columns);
  }

  public async query(query: string, values: unknown[]) {
    return this.withConnection(async (conn) => {
      await this.setTimeZone(conn);

      return conn.execute(query, values);
    });
  }

  protected setTimeZone(conn: MySQLConnection) {
    return conn.execute(`SET time_zone = '${this.config.storeTimezone || '+00:00'}'`, []);
  }

  public async release() {

View on GitHub (pinned to 7d981676b3)

Solutions

  1. Add `sqlAlias: 'short_name'` to the cube definition in the data model to shorten the generated table name.
  2. Shorten the cube name or pre-aggregation name in the schema.
  3. Shorten any deployment prefix (e.g., CUBEJS_DB_NAME or schema prefix) contributing to the identifier.
  4. If unavoidable, use a database with a longer identifier limit.

Example fix

// before
cube('VeryLongSalesTransactionsForNorthAmericaRegionalReporting', { /* ... */ });
// after
cube('VeryLongSalesTransactionsForNorthAmericaRegionalReporting', {
  sqlAlias: 'sales_tx_na',
  /* ... */
});
Defensive patterns

Strategy: validation

Validate before calling

if (quotedTableName.length > 64) {
  throw new Error(`Table name exceeds MySQL's 64-char limit: ${quotedTableName}. Add sqlAlias to the cube.`);
}

Try / catch

try {
  await driver.createTable(name, columns);
} catch (e) {
  if (e.message.includes('longer than 64')) {
    console.error('Add sqlAlias to the cube definition');
  }
  throw e;
}

Prevention

When it happens

Trigger: A pre-aggregation (rollup) table is uploaded via `uploadTableWithIndexes` -> `createTable`, where the generated quoted table name (derived from cube/pre-aggregation naming) exceeds 64 characters.

Common situations: Cubes with very long names or long pre-aggregation names in multi-tenant setups where prefixes/segment names are appended to the rollup table name.

Related errors


AI-assisted analysis of cube-js/cube@7d981676b3 (2026-09-02). Data as JSON: /api/errors/5f0355ebc50c3c3f. Report an issue: GitHub.