{"id":43778,"library":"ruoyi-eggjs-mysql","title":"ruoyi-eggjs-mysql","description":"Egg.js MySQL plugin based on mysql2, providing connection pool management and a simple API wrapper (select, insert, update, delete). Version 1.1.15 supports egg 2.x and 3.x (not 1.x). Key features: optional camelCase field conversion (v1.1.7+), timezone and dateStrings options (v1.1.14+), built-in transaction support, and automatic SQL execution time logging in development. Distinguishes from egg-mysql by being based on mysql2, offering camelCase conversion, and stricter Node.js version requirement (>=16).","status":"active","version":"1.1.15","language":"javascript","source_language":"en","source_url":"https://github.com/undsky/ruoyi-eggjs-mysql","tags":["javascript","egg","eggPlugin","egg-plugin","mysql","mysql2"],"install":[{"cmd":"npm install ruoyi-eggjs-mysql","lang":"bash","label":"npm"},{"cmd":"yarn add ruoyi-eggjs-mysql","lang":"bash","label":"yarn"},{"cmd":"pnpm add ruoyi-eggjs-mysql","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"MySQL database driver","package":"mysql2","optional":false}],"imports":[{"note":"Must be configured as an Egg.js plugin, not imported directly in code.","wrong":"// common mistake: using require in plugin config\nmodule.exports = {\n  mysql: { enable: true, package: 'egg-mysql' } // wrong package name\n}","symbol":"plugin configuration","correct":"// config/plugin.js\nmodule.exports = {\n  mysql: {\n    enable: true,\n    package: 'ruoyi-eggjs-mysql',\n  },\n};"},{"note":"app.mysql is a getter that returns a proxy object; direct destructuring may not work.","wrong":"// common mistake: destructuring app.mysql\nconst { mysql } = app; // mysql is undefined because it is a getter","symbol":"app.mysql","correct":"const result = await app.mysql.select('SELECT * FROM users');"},{"note":"For multi-instance, use get() method, not property access.","wrong":"const db = app.mysql.db1; // not a property","symbol":"app.mysql.get","correct":"const db = app.mysql.get('db1');"}],"quickstart":{"code":"// config/plugin.js\nmodule.exports = {\n  mysql: {\n    enable: true,\n    package: 'ruoyi-eggjs-mysql',\n  },\n};\n\n// config/config.default.js\nconfig.mysql = {\n  client: {\n    host: process.env.MYSQL_HOST ?? '127.0.0.1',\n    port: 3306,\n    user: process.env.MYSQL_USER ?? 'root',\n    password: process.env.MYSQL_PASSWORD ?? '',\n    database: 'test',\n  },\n};\n\n// app/controller/user.js\nasync queryUser() {\n  const { app } = this.ctx;\n  const users = await app.mysql.select('SELECT * FROM users WHERE age > ?', [18]);\n  console.log(users);\n}","lang":"javascript","description":"Shows plugin configuration, single-instance client setup, and a simple select query with parameterized SQL."},"warnings":[{"fix":"Upgrade Node.js to >=16 and egg to 2.x or 3.x.","message":"Node.js >= 16 required; egg 1.x is not supported (only 2.x and 3.x).","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"If you enable camelCase, update all field references from snake_case to camelCase.","message":"camelCase option may change default behavior. It is false by default, but enabling it in existing projects can break field mapping.","severity":"deprecated","affected_versions":">=1.1.7"},{"fix":"Add dateStrings: false to mysql config for Date object returns.","message":"The plugin sets dateStrings to true by default, returning dates as strings. If you expect Date objects, set dateStrings: false in config.","severity":"gotcha","affected_versions":">=1.1.14"},{"fix":"Always use ? for parameters. For named placeholders, use a separate library.","message":"Parameterized queries use the mysql2 pattern (placeholders with ?), not named placeholders. Using named placeholders will fail silently.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Do not call app.mysql.end() or similar; pool lifecycle is automatic.","message":"There is no default 'end' method on the app.mysql object; closing the connection pool is handled automatically on app close.","severity":"breaking","affected_versions":">=1.0.0"}],"env_vars":null,"search_vec":"'1':34 '1.1.15':25 '16':79 '2':28 '3':31 'api':18 'automat':54 'base':8,68 'built':49 'built-in':48 'camelcas':39,72 'connect':12 'convers':41,73 'datestr':45 'delet':23 'develop':60 'distinguish':61 'egg':27,64,81,84 'egg-mysql':63 'egg-plugin':83 'egg.js':5 'eggj':3 'eggplugin':82 'execut':56 'featur':37 'field':40 'insert':21 'javascript':80 'key':36 'log':58 'manag':14 'mysql':4,6,65,86 'mysql2':10,70,87 'node.js':76 'offer':71 'option':38,46 'plugin':7,85 'pool':13 'provid':11 'requir':78 'ruoyi':2 'ruoyi-eggjs-mysql':1 'select':20 'simpl':17 'sql':55 'stricter':75 'support':26,52 'time':57 'timezon':43 'transact':51 'updat':22 'v1.1.14':47 'v1.1.7':42 'version':24,77 'wrapper':19 'x':29,32,35","created_at":"2026-06-05T17:01:26.446364+00:00","updated_at":"2026-06-05T17:01:26.446364+00:00","problems":[{"fix":"Ensure plugin is enabled in config/plugin.js and mysql config is set in config/config.default.js","cause":"app.mysql is undefined because the plugin is not enabled or configured","error":"TypeError: Cannot read properties of undefined (reading 'select')"},{"fix":"Check MYSQL_HOST environment variable or config; ensure MySQL server is running and accessible.","cause":"MySQL host or port is unreachable","error":"Error: getaddrinfo EAI_AGAIN (or ECONNREFUSED) on connect to MySQL"},{"fix":"Verify MYSQL_USER, MYSQL_PASSWORD, and that the user has access to the specified database.","cause":"Wrong credentials or user permissions","error":"Error: ER_ACCESS_DENIED_ERROR: Access denied for user 'user'@'host'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/undsky/ruoyi-eggjs-mysql#readme","github":"https://github.com/undsky/ruoyi-eggjs-mysql","docs":null,"changelog":null,"pypi":null,"npm":"ruoyi-eggjs-mysql","openapi_spec":null,"status_page":null,"smithery":null,"categories":["database"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-05","next_check":"2026-09-03","install_tag":null}}