I wrote a js script and it works fine locally, however, when I deploy it to my ubuntu-server I can not connect to the mysql-database. I am getting following error-message:
Error: Access denied for user 'root'@'localhost'
at PromisePool.query (/root/platformbackend/node_modules/mysql2/promise.js:330:22)
at IdentificationRepositoryImpl.<anonymous> (/root/platformbackend/src/Repository/IdentificationRepositoryImpl.ts:19:14)
at step (/root/platformbackend/src/Repository/IdentificationRepositoryImpl.ts:46:23)
at Object.next (/root/platformbackend/src/Repository/IdentificationRepositoryImpl.ts:27:53)
at /root/platformbackend/src/Repository/IdentificationRepositoryImpl.ts:21:71
at new Promise (<anonymous>)
at __awaiter (/root/platformbackend/src/Repository/IdentificationRepositoryImpl.ts:17:12)
at IdentificationRepositoryImpl.setupTable (/root/platformbackend/src/Repository/IdentificationRepositoryImpl.ts:61:16)
at /root/platformbackend/src/SitServer/SitServer.ts:60:24
at Array.map (<anonymous>) {
code: 'ER_ACCESS_DENIED_NO_PASSWORD_ERROR',
errno: 1698,
sqlState: '28000',
sqlMessage: "Access denied for user 'root'@'localhost'"
The code, the error originates from is (in condensed form) following:
const connectionOptions = {
host: process.env.DB_HOST || 'localhost',
user: process.env.DB_USER || 'root',
password: process.env.DB_PASSWORD || '',
database: process.env.DB_NAME || 'test_db',
};
const connection = createPool(connectionOptions);
const insertId = await connection
.promise()
.query(sql)
.then(result => result)
.catch(error => console.error(error));
Now I am confused, what the error code ER_ACCESS_DENIED_NO_PASSWORD_ERROR
actually means.
- Does it mean, that I provided an empty password?
- Or does it mean, that it didn't receive a password and it thinks there is no password provided (not even an empty one)?
- Or does it mean, that it doesn't expect a password to be provided, but it got one?
I have tried...
- ...setting the root's password to an empty string and providing an empty string as password
- ...setting the root's password to an empty string and providing no password entry in
connectionOptions
- ...setting the root's password and providing the password in the password entry in
connectionOptions
but all with the same error as outcome.
Some research and approaches I also already tried:
- MariaDB connection to ExpressJS access denied no password error
- Access denied for user 'root'@'localhost' (using password: YES) (Mysql::Error)
- ERROR 1698 (28000): Access denied for user 'root'@'localhost' at Ubuntu 18.04
- ER_ACCESS_DENIED_ERROR: #591
- MySQL :: MySQL 8.0 Reference Manual :: B.3.1 Server Error Message Reference
Thank you for any help, pointing me in the right direction. If I'm missing any debugging-details, I'm happy to provide them upon request.
Sidenote: I know I shouldn't use the root-user, it's a testing server.