# PhpMyAdmin and MariaDB connection problem



## bigart (Feb 2, 2021)

Hi,
I'm trying to configure MariaDB and PhpMyAdmin.

When I'm trying to log in by PhpMyAdmin to MariaDB I get:


```
Packets out of order. Expected 0 received 1. Packet size=67
http://192.168.1.15/phpmyadmin/themes/dot.gif
mysqli_real_connect(): Error while reading greeting packet. PID=86156

mysqli_real_connect(): (HY000/2006): MySQL server has gone away
```

MariaDB working fine - I can log in by command line using the same credentials.
Where I should to look to find the problem ?


----------



## SirDice (Feb 2, 2021)

Packets out of order suggests some serious network related issues. How is the host that runs PHPMyAdmin connected to the host that runs MariaDB?


----------



## bigart (Feb 2, 2021)

SirDice said:


> Packets out of order suggests some serious network related issues. How is the host that runs PHPMyAdmin connected to the host that runs MariaDB?


I'm trying to connect from the machine in same network (LAN), Mariadb and phpmyadmin both installed in the same server.


----------



## SirDice (Feb 2, 2021)

bigart said:


> Mariadb and phpmyadmin both installed in the same server.


What are you using as the connection string in PHPMyAdmin? In this case it should be 'localhost' and the connection would use the socket in /tmp/mysql.sock.


----------



## bigart (Feb 2, 2021)

SirDice said:


> What are you using as the connection string in PHPMyAdmin? In this case it should be 'localhost' and the connection would use the socket in /tmp/mysql.sock.


It's working - thank you but I only changed one parameter - from 127.0.0.1 to localhost.

my connection settings:

```
/* Authentication type */
$cfg['Servers'][$i]['auth_type'] = 'cookie';
/* Server parameters */
$cfg['Servers'][$i]['host'] = 'localhost';
$cfg['Servers'][$i]['compress'] = false;
$cfg['Servers'][$i]['AllowNoPassword'] = false;
```

SirDice sorry but I need more details. Where I should set socket to /tmp/mysql.sock. ?


----------



## SirDice (Feb 2, 2021)

bigart said:


> Where I should set socket to /tmp/mysql.sock. ?


That's already set in /usr/local/etc/mysql/my.cnf by default. 


```
[client]
port                            = 3306
socket                          = /tmp/mysql.sock
```


```
[mysqld]
user                            = mysql
port                            = 3306
socket                          = /tmp/mysql.sock
```


----------



## bigart (Feb 3, 2021)

phpmyadmin working fine - I can create databases, users etc.

Now I'm trying to configure my crm and I have similar problem:


```
Error: (2006) MySQL server has gone away

Please check database settings in "config/database.php" file.
```


My connection file:

```
// define database connection
  define('DB_SERVER', 'localhost:3306'); // eg, localhost - should not be empty for productive servers
  define('DB_SERVER_USERNAME', 'mysql');
  define('DB_SERVER_PASSWORD', 'passwd');
  define('DB_SERVER_PORT', '3306');        
  define('DB_DATABASE', 'projects');
```

my.conf

```
# This group is read both by the client and the server
# use it for options that affect everything, see
# https://mariadb.com/kb/en/configuring-mariadb-with-option-files/#option-groups
#
[client-server]
port    = 3306
socket  = /var/run/mysql/mysql.sock


#
# include *.cnf from the config directory
#
!includedir /usr/local/etc/mysql/conf.d/
```

client.cnf


```
# Options specific to client applications, see
# https://mariadb.com/kb/en/configuring-mariadb-with-option-files/#client-option-groups

# Options specific to all client programs
[client]
# port                  = 3306 # inherited from /usr/local/etc/mysql/my.cnf
# socket                = /var/run/mysql/mysql.sock # inherited from /usr/local/etc/mysql/my.cnf

# Options specific to MariaDB client programs
[client-mariadb]

#
## Options for specific client Tools
#

# Options read by `mysql`
# Renamed from [mysql] starting with MariaDB 10.4.6.
[mariadb-client]        Options read by mysql. Available starting with MariaDB 10.4.6.
prompt                  = \u@\h [\d]>\_
no_auto_rehash
max_allowed_packet      = 256M

# Options read by `mysqldump`
# Renamed from [mysqldump] starting with MariaDB 10.4.6.

[mariadb-dump]
max_allowed_packet      = 256M
quote_names
quick

# Options read by `mysqladmin`
# Renamed from [mysqladmin] starting with MariaDB 10.4.6.
[mariadb-admin]


# Options read by `mysqlbinlog`
# Renamed from [mysqlbinlog] starting with MariaDB 10.4.6.
[mariadb-binlog]

# Options read by `mysqlcheck`
# Renamed from [mysqlcheck] starting with MariaDB 10.4.6.
[mariadb-check]


# Options read by `mysqlimport`
# Renamed from [mysqlimport] starting with MariaDB 10.4.6.
[mariadb-import]

# Options read by `mysqlshow`
# Renamed from [mysqlshow] starting with MariaDB 10.4.6.
[mariadb-show]

# Options read by `mysqlslap`
# Renamed from [mysqlslap]  starting with MariaDB 10.4.6.
[mariadb-slap]
```

server.cnf


```
# Options specific to server applications, see
# https://mariadb.com/kb/en/configuring-mariadb-with-option-files/#server-option-groups

# Options specific to all server programs
[server]

# Options specific to MariaDB server programs
[server-mariadb]

#
# Options for specific server tools
#

[mysqld]
user                            = mysql
#user                           = root
# port                          = 3306 # inherited from /usr/local/etc/mysql/my.cnf
# socket                        = /var/run/mysql/mysql.sock # inherited from /usr/local/etc/mysql/my.cnf

bind-address                    = 127.0.0.1

basedir                         = /usr/local
datadir                         = /var/db/mysql
net_retry_count                 = 16384
log_error                       = /var/log/mysql/mysqld.err
# [mysqld] configuration for ZFS
# From https://www.percona.com/resources/technical-presentations/zfs-mysql-percona-technical-webinar
# Create separate datasets for data and logs, eg
# zroot/mysql      compression=on recordsize=128k atime=off
# zroot/mysql/data recordsize=16k
# zroot/mysql/logs
# datadir                       = /var/db/mysql/data
# innodb_log_group_home_dir     = /var/db/mysql/log
# audit_log_file                = /var/db/mysql/log/audit.log
# general_log_file              = /var/db/mysql/log/general.log
# log_bin                       = /var/db/mysql/log/mysql-bin
# relay_log                     = /var/db/mysql/log/relay-log
# slow_query_log_file           = /var/db/mysql/log/slow.log
# innodb_doublewrite            = 0
# innodb_flush_method           = O_DSYNC

# Options read by `mariadb_safe`
# Renamed from [mysqld_safe] starting with MariaDB 10.4.6.
[mariadb-safe]

# Options read my `mariabackup`
[mariabackup]

# Options read by `mysql_upgrade`
# Renamed from [mysql_upgrade] starting with MariaDB 10.4.6.
[mariadb-upgrade]

# Specific options read by the mariabackup SST method
[sst]

# Options read by `mysqlbinlog`
# Renamed from [mysqlbinlog] starting with MariaDB 10.4.6.
[mariadb-binlog]

# Options read by `mysqladmin`
# Renamed from [mysqladmin] starting with MariaDB 10.4.6.
[mariadb-admin]
```



Tables in database were created during the installation so the connection is right.
It's happening when I'm trying to login.


----------



## SirDice (Feb 3, 2021)

bigart said:


> My connection file:


Remove the port from the DB_SERVER string.

```
define('DB_SERVER', 'localhost');
```



bigart said:


> my.conf


I assumed you were using MySQL 5.7 because that's the default. MariaDB is configured slightly different, the socket is set to /var/run/mysql/mysql.sock. Just leave those settings as-is. You don't need to worry about, the defaults are fine.


----------



## bigart (Feb 4, 2021)

SirDice said:


> Remove the port from the DB_SERVER string.
> 
> ```
> define('DB_SERVER', 'localhost');
> ...


Working


----------

