{"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":24,"sourceCode":"// 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\n// Logger is used to log critical error messages.","sourceCodeStart":6,"sourceCodeEnd":42,"githubUrl":"https://github.com/go-sql-driver/mysql/blob/c426bd93799de0f0e094c8f0582872c529d0ed0a/errors.go#L6-L42","documentation":"ErrNativePassword is returned at auth.go:306 when the server requests the `mysql_native_password` plugin but the DSN has disabled it (AllowNativePasswords == false). Note AllowNativePasswords defaults to TRUE, so this error only appears when a caller explicitly set `allowNativePasswords=false`.","triggerScenarios":"DSN contains `allowNativePasswords=false` AND the MySQL account authenticates with mysql_native_password (the default plugin on MySQL 5.7 and many 8.x setups). The auth switch at auth.go:304 hits the !AllowNativePasswords branch and returns the error.","commonSituations":"A developer copied `allowNativePasswords=false` from a sample DSN intending to require caching_sha2_password, but the server/user still uses native password; migrating to 8.x default plugin without changing the DSN flag back.","solutions":["Remove `allowNativePasswords=false` from the DSN (default is true) so the driver can use the native plugin.","Or set `allowNativePasswords=true` explicitly.","If you truly require a different plugin, change the account's plugin on the server with ALTER USER."],"exampleFix":"// before\ndsn := \"u:p@tcp(host:3306)/db?allowNativePasswords=false\"\n// after\ndsn := \"u:p@tcp(host:3306)/db\"","handlingStrategy":"validation","validationCode":"dsn = strings.ReplaceAll(dsn, \"allowNativePasswords=false\", \"\")\n// rely on the default (true)","typeGuard":null,"tryCatchPattern":"if errors.Is(err, mysql.ErrNativePassword) {\n    // remove allowNativePasswords=false and retry\n}","preventionTips":["Leave AllowNativePasswords at its default (true).","Only disable it when intentionally forcing a different plugin and the account is updated to match.","Review copied DSN snippets."],"tags":["auth","config"],"analyzedSha":"c426bd93799de0f0e094c8f0582872c529d0ed0a","analyzedAt":"2026-08-04T21:52:59.219Z","schemaVersion":2}