Can't Connect To MySQL

Installed with snap, Ubuntu 18.04

nextcloud was successfully running, but I can’t connect to MySQL server, please help me.

here is command

#mysql -h 127.0.0.1 -u nextcloud -pX*********HJF

and the result is

mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

here is all content in config/config.php, hasn’t modify anything

<?php
$CONFIG = array (
  'apps_paths' =>
  array (
    0 =>
    array (
      'path' => '/snap/nextcloud/current/htdocs/apps',
      'url' => '/apps',
      'writable' => false,
    ),
    1 =>
    array (
      'path' => '/var/snap/nextcloud/current/nextcloud/extra-apps',
      'url' => '/extra-apps',
      'writable' => true,
    ),
  ),
  'supportedDatabases' =>
  array (
    0 => 'mysql',
  ),
  'memcache.locking' => '\\OC\\Memcache\\Redis',
  'memcache.local' => '\\OC\\Memcache\\Redis',
  'redis' =>
  array (
    'host' => '/tmp/sockets/redis.sock',
    'port' => 0,
  ),
  'instanceid' => '[REMOVED]',
  'passwordsalt' => '[REMOVED]',
  'secret' => '[REMOVED]',
  'trusted_domains' =>
  array (
    0 => '127.0.0.1',
    1 => '[REMOVED]',
    2 => '192.168.11.120',
  ),
  'datadirectory' => '/var/snap/nextcloud/common/nextcloud/data',
  'dbtype' => 'mysql',
  'version' => '15.0.7.0',
  'overwrite.cli.url' => 'http://127.0.0.1',
  'dbname' => 'nextcloud',
  'dbhost' => 'localhost:/tmp/sockets/mysql.sock',
  'dbport' => '',
  'dbtableprefix' => 'oc_',
  'mysql.utf8mb4' => true,
  'dbuser' => '[REMOVED]',
  'dbpassword' => '[REMOVED]',
  'installed' => true,
  'maintenance' => false,
  'loglevel' => 2,
);
1 Like

is the mysql-server running and listening on 127.0.0.1? i suggest you check/restart it and try again.
(also, i think you’d be much safer not posting usernames with passwords online here.)
GOOD LUCK!

Man! Don’t post all your usernames and passwords!
I removed them from your post, but you should treat your server insecure and compromised now.

Regarding your question; while NC connects to the mysql socket /tmp/sockets/mysql.sockand your mysql command tries to connect to /var/run/mysqld/mysqld.sock by default, I suggest you try with the following command:

mysql --socket=/tmp/sockets/mysql.sock -u nextcloud -p

If you use nextcloud-snap, you need to use the included cli-utility from nextcloud-snap:

sudo nextcloud.mysql-client -S /tmp/sockets/mysql.sock -u nextcloud -p

See here:

4 Likes

I use nextcloud in local network, so I post all. XD Anyway thanks a lot.

Thanks! In my case this slight variation worked:

sudo nextcloud.mysql-client -S /tmp/sockets/mysql.sock nextcloud

That command just gives an error:
ERROR 1045 (28000): Access denied for user ‘nextcloud’@‘localhost’ (using password: NO)

It neither accepts the password I have used for all the setup, nor an empty password.

Can you try without any options (adapt the database name ‘nextcloud’ to fit the according value in your config.php)?

sudo nextcloud.mysql-client nextcloud