Common SQL Errors

MySQL Error 1126: ER_CANT_OPEN_LIBRARY – How to Fix and Prevent

Galaxy Team
August 5, 2025

MySQL cannot load a required shared library or plugin, returning ER_CANT_OPEN_LIBRARY (error 1126).

Sign up for the latest in common SQL errors from the Galaxy Team!
Welcome to the Galaxy, Guardian!
You'll be receiving a confirmation email

Follow us on twitter :)
Oops! Something went wrong while submitting the form.

What is MySQL error 1126?

MySQL Error 1126: ER_CANT_OPEN_LIBRARY appears when the server fails to load a required shared library or plugin. Incorrect plugin_dir, missing .so/.dll files, or inadequate file permissions usually cause it. Reinstall the library, correct the path, and grant read-execute access to resolve the issue.

Error Highlights

Typical Error Message

Can't open shared library '%s' (errno: %d %s)

Error Type

System Error

Language

MySQL

Symbol

ER_CANT_OPEN_LIBRARY

Error Code

1126

SQL State

Explanation

Table of Contents

What is MySQL Error 1126: ER_CANT_OPEN_LIBRARY?

MySQL raises error 1126 with the message "Can't open shared library '%s' (errno: %d %s)" when it cannot load a dynamic library or plugin at startup or during a CREATE FUNCTION, INSTALL PLUGIN, or LOAD DATA operation.

The server relies on the operating system's dynamic linker, so any path, permission, or dependency issue blocks the load and triggers this error.

Fixing the problem quickly is important because MySQL may refuse to start, skip loading essential plugins such as authentication or storage engines, and leave applications unusable until the library issue is resolved.

What Causes This Error?

The library file is missing from the directory specified by the plugin_dir system variable or hard-coded path in CREATE FUNCTION.

A filename typo or version mismatch also prevents loading and throws error 1126.

File permissions often block the MySQL daemon (mysqld) from reading or executing the .so or .dll file. SELinux or AppArmor profiles can further restrict access and surface the same error code.

Unresolved dependent libraries at the OS level cause the dynamic loader to fail.

ldd on Linux or Dependency Walker on Windows reveals missing libc, libstdc++, or OpenSSL versions that break plugin loading.

How to Fix MySQL Error 1126

Verify plugin_dir with SHOW VARIABLES LIKE 'plugin_dir'; and confirm the target .so/.dll file exists. Copy or reinstall the plugin package if it is missing.

Correct file permissions by running chmod 755 libmyplugin.so and chown mysql:mysql libmyplugin.so. Ensure mysqld has execute rights.

Resolve dependent libraries.

On Linux, run ldd libmyplugin.so and install any "not found" packages with the system package manager. On Windows, place required DLLs in the same folder or a directory in the PATH.

Common Scenarios and Solutions

After an OS upgrade, OpenSSL or glibc versions change and existing plugins fail to link. Recompile the plugin against new headers or install MySQL’s matching plugin build.

When deploying on Alpine Linux, musl libc replaces glibc, so precompiled Oracle or Percona plugins refuse to load.

Use community builds compiled for musl or switch to a glibc-based image.

Best Practices to Avoid This Error

Pin MySQL and plugin versions in configuration management tools and container images.

Always deploy compatible binaries together to avoid mismatch.

Automate validation with a startup script that runs INSTALL PLUGIN IF NOT EXISTS and logs failures before traffic reaches the database.

Monitor the MySQL error log and trigger alerts on ER_CANT_OPEN_LIBRARY appearances, enabling proactive remediation.

Related Errors and Solutions

Error 1127 (ER_DYNAMIC_SQL_ERROR) often follows 1126 when a UDF fails to load and a statement still references it.

Remove or fix the UDF.

Error 1524 (ER_PASSWORD_NO_MATCH) may appear if the authentication plugin failed to load due to 1126, causing user logins to break. Install the auth plugin and retry.

.

Common Causes

Incorrect plugin_dir path

plugin_dir points to an outdated or wrong directory so mysqld cannot locate the requested library.

Missing .so/.dll file

The plugin package was not installed on the host or was deleted during a cleanup, leaving MySQL with a dangling reference.

File permission issues

The MySQL service user lacks read or execute rights on the library file, blocking the operating system loader.

Unmet binary dependencies

The library itself links to other shared objects that are absent or incompatible on the system.

Security modules blocking access

SELinux, AppArmor, or antivirus software intercepts mysqld’s attempt to load the file and denies it.

.

Related Errors

FAQs

Does this error only occur on Linux?

No. Windows shows the same error when MySQL cannot load a DLL. Path and permission concepts apply across platforms.

Can I ignore error 1126 if MySQL starts?

Ignoring it risks runtime failures. Missing storage engines or authentication plugins can break queries and connections later.

How does Galaxy help prevent ER_CANT_OPEN_LIBRARY?

Galaxy surfaces real-time error logs inside its SQL editor, letting engineers spot plugin load failures immediately. Version-controlled configuration in Galaxy keeps plugin_dir settings consistent across environments.

Is recompilation always necessary?

No. Reinstalling the correct binary or adding missing dependencies fixes most cases. Recompile only when plugin source and server version mismatch.

Start Querying with the Modern SQL Editor Today!
Welcome to the Galaxy, Guardian!
You'll be receiving a confirmation email

Follow us on twitter :)
Oops! Something went wrong while submitting the form.

Check out some other errors

Trusted by top engineers on high-velocity teams
Aryeo Logo
Assort Health
Curri
Rubie Logo
Bauhealth Logo
Truvideo Logo