{"record":{"id":"add5c07c672be97c","repo":"go-sql-driver/mysql","slug":"this-user-requires-mysql-native-password-authentic","errorCode":null,"errorMessage":"this user requires mysql native password authentication","messagePattern":"this user requires mysql native password authentication","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"errors.go","lineNumber":23,"sourceCode":"// This Source Code Form is subject to the terms of the Mozilla Public\n// License, v. 2.0. If a copy of the MPL was not distributed with this file,\n// You can obtain one at http://mozilla.org/MPL/2.0/.\n\npackage mysql\n\nimport (\n\t\"errors\"\n\t\"fmt\"\n\t\"log\"\n\t\"os\"\n)\n\n// Various errors the driver might return. Can change between driver versions.\nvar (\n\tErrInvalidConn       = errors.New(\"invalid connection\")\n\tErrMalformPkt        = errors.New(\"malformed packet\")\n\tErrNoTLS             = errors.New(\"TLS requested but server does not support TLS\")\n\tErrCleartextPassword = errors.New(\"this user requires clear text authentication. If you still want to use it, please add 'allowCleartextPasswords=1' to your DSN\")\n\tErrNativePassword    = errors.New(\"this user requires mysql native password authentication\")\n\tErrOldPassword       = errors.New(\"this user requires old password authentication. If you still want to use it, please add 'allowOldPasswords=1' to your DSN. See also https://github.com/go-sql-driver/mysql/wiki/old_passwords\")\n\tErrUnknownPlugin     = errors.New(\"this authentication plugin is not supported\")\n\tErrOldProtocol       = errors.New(\"MySQL server does not support required protocol 41+\")\n\tErrPktSync           = errors.New(\"commands out of sync. You can't run this command now\")\n\tErrPktSyncMul        = errors.New(\"commands out of sync. Did you run multiple statements at once?\")\n\tErrPktTooLarge       = errors.New(\"packet for query is too large. Try adjusting the `Config.MaxAllowedPacket`\")\n\tErrBusyBuffer        = errors.New(\"busy buffer\")\n\n\t// errBadConnNoWrite is used for connection errors where nothing was sent to the database yet.\n\t// If this happens first in a function starting a database interaction, it should be replaced by driver.ErrBadConn\n\t// to trigger a resend. Use mc.markBadConn(err) to do this.\n\t// See https://github.com/go-sql-driver/mysql/pull/302\n\terrBadConnNoWrite = errors.New(\"bad connection\")\n)\n\nvar defaultLogger = Logger(log.New(os.Stderr, \"[mysql] \", log.Ldate|log.Ltime))\n","sourceCodeStart":5,"sourceCodeEnd":41,"githubUrl":"https://github.com/go-sql-driver/mysql/blob/03d76c7e07908e255ce62d126d07ede3f2365d86/errors.go#L5-L41","documentation":"ErrNativePassword is returned from auth() (auth.go:306) when the server requires the mysql_native_password plugin but the DSN explicitly disabled it (allowNativePasswords=false). Because AllowNativePasswords defaults to true (dsn.go:97), this error only appears when an operator deliberately turned native auth off.","triggerScenarios":"Connecting with allowNativePasswords=false in the DSN to a server/account whose auth plugin is mysql_native_password (the historical default for MySQL < 8.0 and all MariaDB releases).","commonSituations":"Hardening a DSN by disabling native passwords in anticipation of caching_sha2_password-only servers, then pointing it at an older MySQL 5.7 or MariaDB instance; copying a hardened DSN between environments with different server versions.","solutions":["Remove allowNativePasswords=false (or set it true) so the driver can answer the native-password challenge.","Upgrade/switch the account to caching_sha2_password (MySQL 8+) so native auth is genuinely unnecessary.","Keep the flag disabled only if every reachable server is caching_sha2_password-capable."],"exampleFix":"// before\ndsn := \"user:pass@tcp(mysql57:3306)/db?allowNativePasswords=false\"\n// -> ErrNativePassword\n\n// after\ndsn := \"user:pass@tcp(mysql57:3306)/db\"","handlingStrategy":"validation","validationCode":"// Do not disable native auth unless every target server is\n// caching_sha2_password-only.\ndsn := \"user:pass@tcp(host:3306)/db\"\n// omit allowNativePasswords=false unless you have verified the server","typeGuard":"func isNativePasswordDenied(err error) bool {\n    return errors.Is(err, mysql.ErrNativePassword)\n}","tryCatchPattern":"if errors.Is(err, mysql.ErrNativePassword) {\n    // remove allowNativePasswords=false from the DSN, or switch the\n    // account to caching_sha2_password, then retry.\n}","preventionTips":["Leave allowNativePasswords at its default (true) for MySQL 5.x / MariaDB.","Audit DSNs copied between environments for hardened flags that don't apply.","Standardize on caching_sha2_password before disabling native auth."],"tags":["authentication","config","compatibility"],"backgroundTag":null,"analyzedSha":"03d76c7e07908e255ce62d126d07ede3f2365d86","analyzedAt":"2026-08-07T10:39:17.340Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}