error message
troubleshooting
unknown user
client issue
computer problems

what does Unknown user client mean?

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

Introduction

The "Unknown user client" error typically appears in database systems (MySQL, PostgreSQL) or network services when a client tries to authenticate with a username that does not exist on the server. In MySQL, the full error is often ERROR 1045 (28000): Access denied for user 'username'@'host'. This means the user account does not exist for the connecting host, the password is wrong, or the user lacks the required privileges. The fix is to verify the user exists, create it if needed, and grant appropriate permissions from the correct host.

MySQL: Access Denied / Unknown User

The most common context for this error is MySQL:

 
ERROR 1045 (28000): Access denied for user 'myapp'@'172.17.0.2' (using password: YES)

Check If the User Exists

sql
1-- List all MySQL users and their hosts
2SELECT user, host FROM mysql.user;
3
4-- Check for a specific user
5SELECT user, host, authentication_string FROM mysql.user
6WHERE user = 'myapp';

MySQL users are identified by 'user'@'host'. A user 'myapp'@'localhost' is different from 'myapp'@'%' (any host).

Create the User

sql
1-- Create user for all hosts
2CREATE USER 'myapp'@'%' IDENTIFIED BY 'secure_password';
3
4-- Or for a specific host/subnet
5CREATE USER 'myapp'@'172.17.%' IDENTIFIED BY 'secure_password';
6
7-- Grant privileges
8GRANT ALL PRIVILEGES ON mydb.* TO 'myapp'@'%';
9FLUSH PRIVILEGES;

Reset a Password

sql
ALTER USER 'myapp'@'%' IDENTIFIED BY 'new_password';
FLUSH PRIVILEGES;

PostgreSQL: No pg_hba.conf Entry

PostgreSQL uses a different message:

 
FATAL: no pg_hba.conf entry for host "192.168.1.100", user "myapp", database "mydb"

Fix pg_hba.conf

bash
# Find the config file
sudo -u postgres psql -c "SHOW hba_file;"
# /etc/postgresql/15/main/pg_hba.conf

Add an entry for the client:

 
# TYPE  DATABASE  USER    ADDRESS         METHOD
host    mydb      myapp   192.168.1.0/24  md5
host    all       all     0.0.0.0/0       md5
bash
# Reload configuration
sudo systemctl reload postgresql

Create the PostgreSQL User

sql
1-- Connect as superuser
2sudo -u postgres psql
3
4-- Create role
5CREATE ROLE myapp WITH LOGIN PASSWORD 'secure_password';
6
7-- Grant database access
8GRANT ALL PRIVILEGES ON DATABASE mydb TO myapp;

MongoDB: Authentication Failed

 
MongoServerError: Authentication failed
javascript
1// Connect to admin database
2mongosh admin
3
4// Create user
5db.createUser({
6  user: "myapp",
7  pwd: "secure_password",
8  roles: [{ role: "readWrite", db: "mydb" }]
9});
10
11// Verify
12db.getUsers();

SSH: Permission Denied

 
Permission denied (publickey,password).
bash
1# Check if the user exists on the server
2grep myuser /etc/passwd
3
4# Create the user if needed
5sudo useradd -m myuser
6sudo passwd myuser
7
8# Check SSH config allows password authentication
9sudo grep PasswordAuthentication /etc/ssh/sshd_config

Docker / Kubernetes Context

In containerized environments, "unknown user" often means the application is connecting with wrong credentials:

yaml
1# docker-compose.yml
2services:
3  db:
4    image: mysql:8
5    environment:
6      MYSQL_ROOT_PASSWORD: rootpass
7      MYSQL_DATABASE: mydb
8      MYSQL_USER: myapp          # Creates this user automatically
9      MYSQL_PASSWORD: apppass
10
11  app:
12    environment:
13      DB_HOST: db
14      DB_USER: myapp             # Must match MYSQL_USER above
15      DB_PASSWORD: apppass       # Must match MYSQL_PASSWORD above
16      DB_NAME: mydb
bash
# Verify connection from the app container
docker exec -it app_container mysql -h db -u myapp -p mydb

Debugging Checklist

CheckCommand
User exists (MySQL)SELECT user, host FROM mysql.user;
User exists (PostgreSQL)\du in psql
Correct host/IPSELECT user, host FROM mysql.user WHERE user='myapp';
Privileges grantedSHOW GRANTS FOR 'myapp'@'%';
Network accesstelnet db_host 3306
Config reloadedFLUSH PRIVILEGES; (MySQL) or systemctl reload postgresql

Common Pitfalls

  • Confusing MySQL user-host pairs: 'myapp'@'localhost' only allows connections from the local machine. Connections from Docker containers or remote servers come from a different IP and need 'myapp'@'%' or 'myapp'@'container_subnet'.
  • Forgetting FLUSH PRIVILEGES after manual user table changes: If you directly modify mysql.user with INSERT/UPDATE instead of using CREATE USER/GRANT, changes do not take effect until you run FLUSH PRIVILEGES.
  • Using localhost vs 127.0.0.1 in MySQL: On Linux, connecting to localhost uses a Unix socket, while 127.0.0.1 uses TCP. A user granted access for 'myapp'@'127.0.0.1' cannot connect via localhost and vice versa.
  • Not checking the connecting IP address: The error message includes the client IP. Verify that the MySQL user is created for that specific IP or for % (any host). Container IPs change on restart, so use % or a subnet pattern.
  • PostgreSQL pg_hba.conf order matters: PostgreSQL evaluates pg_hba.conf entries top to bottom and uses the first match. A restrictive rule above a permissive one can block access even if a matching allow rule exists below it.

Summary

  • "Unknown user client" means the server cannot find or authenticate the connecting user
  • In MySQL, check mysql.user for the correct user@host pair and run FLUSH PRIVILEGES
  • In PostgreSQL, add an entry to pg_hba.conf and create the role with CREATE ROLE
  • In Docker/Kubernetes, ensure environment variables match between the database and application containers
  • Always verify the client IP address matches the host pattern in the user's grant

Related reading
Free course
Beginner
7 lessons
2 hours
Tackling System Design Interview Problems

A short course that equips you with the skills to approach system design interviews methodically.

Start the free course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

All Rights Reserved.