# Common Issues with MariaDB

## ❌ Error 1045: Access denied for user

### **Symptom**

```
ERROR 1045 (28000): Access denied for user 'username'@'host' (using password: YES)
```

### **Possible causes**

* Incorrect password or unknown user
* User not allowed to connect from the specified host
* MariaDB is not configured to accept connections from your IP address

### **Solutions**

1. Double-check the username and password.
2. Run the following query to see existing users:

   ```sql
   SELECT user, host FROM mysql.user;
   ```
3. Grant privileges with:

   ```sql
   GRANT ALL PRIVILEGES ON *.* TO 'username'@'%' IDENTIFIED BY 'password';
   FLUSH PRIVILEGES;
   ```
4. Verify the `bind-address` in your MariaDB config (`my.cnf` or `my.ini`) allows external access.

***

## ❌ Error 2002: Can't connect to local MySQL server through socket

### **Symptom**

```
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock'
```

### **Possible causes**

* MariaDB server is not running
* The socket file does not exist or is incorrectly configured

### **Solutions**

1. Ensure the MariaDB service is running:

   ```bash
   sudo service mariadb start
   ```
2. Check the socket path in your `my.cnf` config:

   ```bash
   [client]
   socket=/var/run/mysqld/mysqld.sock
   ```
3. Restart MariaDB:

   ```bash
   sudo service mariadb restart
   ```

***

## ❌ MariaDB fails to start

### **Symptom**

Service refuses to start or crashes on launch.

### **Possible causes**

* Corrupt config files
* Permission issues
* Port conflict (e.g. 3306 in use)

### **Solutions**

1. Check the MariaDB error logs (usually in `/var/log/mysql/` or `/var/log/mariadb/`).
2. Ensure data directory and files are owned by the `mysql` user.
3. Confirm port 3306 is not used by another service:

   ```bash
   sudo lsof -i :3306
   ```
4. Fix the issue and restart the service.

***

## ❌ Replication issues

### **Symptom**

Replication fails or slave server is out-of-sync.

### **Possible causes**

* Incorrect replication settings
* Data inconsistency
* Network problems

### **Solutions**

1. Verify replication settings in both master and slave configs.
2. Use `SHOW SLAVE STATUS\G` to check the replication status.
3. If needed, resync data manually or use `mysqldump`.
4. Ensure both servers can communicate over the network.

***

## ❌ Permission errors

### **Symptom**

Access denied when working with specific databases or tables.

### **Possible causes**

* Missing privileges
* Improperly granted permissions

### **Solutions**

1. Check the user's grants:

   ```sql
   SHOW GRANTS FOR 'username'@'host';
   ```
2. Grant the required privileges:

   ```sql
   GRANT ALL PRIVILEGES ON database_name.* TO 'username'@'host';
   FLUSH PRIVILEGES;
   ```
3. Reconnect to apply new privileges.

***

#### If the problem persists, consult the official MariaDB documentation or open a thread on [MariaDB](https://mariadb.com/kb/)
