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

---> MySQL and MariaDB are in conflict.

I've understood that.

----> Uninstall MySQL completely and install MariaDB.

Instead of installing MariaDB,I've installed MySQL. ok. I will try to do the opposite way.
 
Code:
marietto@marietto:/usr/ports/databases # pkg remove mysql57-server mysql57-client

marietto@marietto:/usr/ports/databases # pkg install mariadb105-server mariadb105-client
Updating FreeBSD repository catalogue...
FreeBSD repository is up to date.
All repositories are up to date.
Checking integrity... done (0 conflicting)
The following 2 package(s) will be affected (of 0 checked):

New packages to be INSTALLED:
        mariadb105-client: 10.5.15_3
        mariadb105-server: 10.5.15_3

Number of packages to be installed: 2

The process will require 236 MiB more space.

Proceed with this action? [y/N]: y
[1/2] Installing mariadb105-client-10.5.15_3...
===> Creating groups.
Using existing group 'mysql'.
===> Creating users
Using existing user 'mysql'.
===> Creating homedir(s)
[1/2] Extracting mariadb105-client-10.5.15_3: 100%
[2/2] Installing mariadb105-server-10.5.15_3...
===> Creating groups.
Using existing group 'mysql'.
===> Creating users
Using existing user 'mysql'.
===> Creating homedir(s)
[2/2] Extracting mariadb105-server-10.5.15_3: 100%
=====
Message from mariadb105-client-10.5.15_3:

--
MariaDB respects hier(7) and doesn't check /etc and /etc/mysql for
my.cnf. Please move existing my.cnf files from those paths to
/usr/local/etc/mysql or /usr/local/etc. Sample
configuration files are provided in /usr/local/etc/mysql
and /usr/local/etc/mysql/conf.d.
The rc(8) script no longer uses /var/db/mysql/my.cnf for configuration
nor /var/db/mysql for logs and PID-file.

This port does NOT include the mytop perl script, this is included in
the MariaDB tarball but the most recent version can be found in the
databases/mytop port
=====
Message from mariadb105-server-10.5.15_3:

--
MariaDB respects hier(7) and doesn't check /etc and /etc/mysql for
my.cnf. Please move existing my.cnf files from those paths to
/usr/local/etc/mysql or /usr/local/etc. Sample
configuration files are provided in /usr/local/etc/mysql
and /usr/local/etc/mysql/conf.d.
The rc(8) script no longer uses /var/db/mysql/my.cnf for configuration
nor /var/db/mysql for logs and PID-file.

This port does NOT include the mytop perl script, this is included in
the MariaDB tarball but the most recent version can be found in the
databases/mytop port

marietto@marietto:/usr/ports/databases # service mysql-server start
Starting mysql.

It does not work !

marietto@marietto:/usr/ports/databases # ps ax | grep mysql
6814 0 S+ 0:00.00 grep mysql
 
Code:
marietto@marietto:/usr/local/www/apache24/data # sysrc mysql_enable=yes
mysql_enable: YES -> yes

marietto@marietto:/usr/local/www/apache24/data # mysql_secure_installation

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user. If you've just installed MariaDB, and
haven't set the root password yet, you should just press enter here.

Enter current password for root (enter for none):  ciao

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysql/mysql.sock' (2)
 
Sigh, you still fail to understand the issue here don't you?

The official packages are all built with MySQL 5.7 as the 'default' mysql. Follow the instructions you posted and install databases/mysql57-server instead of MariaDB.

You CANNOT install MariaDB and MySQL at the same time. Packages that require a mysql client (databases/php-mysqli for example) are going to depend on databases/mysql57-client. You CANNOT change the dependencies of those packages.
 
SirDice
There's nothing wrong with MariaDB. WordPress works with both MySQL and MariaDB.
I think MySQL has not yet been completely removed from system and some MySQL settings remain on the system and this is what has caused the conflict. I've had this problem before even with MongoDB. The problem was resolved when I manually deleted the remaining files.
 
There's nothing wrong with MariaDB. WordPress works with both MySQL and MariaDB.
That's not what I'm saying. There's nothing wrong with MariaDB, I have it set as my default.

Doesn't change the fact that the default mysql for the OFFICIAL PACKAGES is MySQL 5.7. Which means you will run into problems if you install MariaDB and expect the rest of the packages to follow, that's not how it works.
 
Am I doing right here ?

Code:
nano /etc/make.conf :

DEFAULT_VERSION+= mysql=10.5m

marietto@marietto:/usr/ports/databases/mysql57-server # make
You're setting MariaDB 10.5 for other ports as the default MySQL database, and trying to compile Oracle MySQL; If you're setting "10.5m" you should type your make command in /usr/ports/databases/mariadb105-server/.
 
Anyway,to avoid confusion,at the moment I'm not trying to build anything from souce. I've tried both these combinations :

Code:
marietto@marietto:/usr/ports/databases # pkg remove mysql57-server mysql57-client
marietto@marietto:/usr/ports/databases # pkg install mariadb105-server mariadb105-client

and

Code:
marietto@marietto:/usr/ports/databases # pkg remove mariadb105-server mariadb105-client
marietto@marietto:/usr/ports/databases # pkg install mysql57-server mysql57-client

but they give the same error. I don't understand what else I could do.
 
Code:
marietto@marietto:/usr/local/www/apache24/data # pkg install mysql57-server

Updating FreeBSD repository catalogue...
FreeBSD repository is up to date.
All repositories are up to date.
Checking integrity... done (3 conflicting)
- mysql57-server-5.7.38 conflicts with mariadb105-server-10.5.15_3 on /usr/local/bin/innochecksum
- mysql57-server-5.7.38 conflicts with mariadb105-client-10.5.15_3 on /usr/local/bin/my_print_defa
ults
- mysql57-client-5.7.38 conflicts with mariadb105-client-10.5.15_3 on /usr/local/bin/mysql
Checking integrity... done (0 conflicting)
The following 5 package(s) will be affected (of 0 checked):

Installed packages to be REMOVED:
mariadb105-client: 10.5.15_3
mariadb105-server: 10.5.15_3

New packages to be INSTALLED:
mysql57-client: 5.7.38
mysql57-server: 5.7.38

Installed packages to be REINSTALLED:
openblas-0.3.20,1

Number of packages to be removed: 2
Number of packages to be installed: 2
Number of packages to be reinstalled: 1

The operation will free 47 MiB.

Proceed with this action? [y/N]: y
[1/5] Deinstalling mariadb105-client-10.5.15_3...
[1/5] Deleting files for mariadb105-client-10.5.15_3: 100%
==> You should manually remove the "mysql" user.
==> You should manually remove the "mysql" group
[2/5] Deinstalling mariadb105-server-10.5.15_3...
[2/5] Deleting files for mariadb105-server-10.5.15_3: 100%
==> You should manually remove the "mysql" user.
==> You should manually remove the "mysql" group
[3/5] Installing mysql57-client-5.7.38...
[3/5] Extracting mysql57-client-5.7.38: 100%
[4/5] Installing mysql57-server-5.7.38...
===> Creating groups.
Using existing group 'mysql'.
===> Creating users
Using existing user 'mysql'.
===> Creating homedir(s)
[4/5] Extracting mysql57-server-5.7.38: 100%
[5/5] Reinstalling openblas-0.3.20,1...
[5/5] Extracting openblas-0.3.20,1: 100%
=====
Message from mysql57-client-5.7.38:

--
This is the mysql CLIENT without the server.
for complete server and client, please install databases/mysql57-server
=====
Message from mysql57-server-5.7.38:

--
Initial password for first time use of MySQL is saved in $HOME/.mysql_secret
ie. when you want to use "mysql -u root -p" first you should see password
in /root/.mysql_secret

MySQL57 has a default /usr/local/etc/mysql/my.cnf,
remember to replace it with your own
or set `mysql_optfile="$YOUR_CNF_FILE` in rc.conf.

marietto@marietto:/usr/local/www/apache24/data # service mysql-server start
Starting mysql.

marietto@marietto:/usr/local/www/apache24/data # service mysql-server status
mysql is not running.

marietto@marietto:/usr/local/www/apache24/data # mysql_secure_installation
mysql_secure_installation: [ERROR] unknown variable 'prompt=\u@\h [\d]>\_'

Securing the MySQL server deployment.

Enter password for user root:
Error: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

marietto@marietto:/usr/local/www/apache24/data # mysql -u root -p
Enter password:  
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
 
I've looked for another tutorial,with the aim to fix the error and I've found this :


even in this tutorial,he has installed mariadb :

Install MariaDB

Install MariaDB database.


Code:
pkg install mariadb105-server mariadb105-client
pkg install mariadb105-server mariadb105-client


Activate and run the MariaDB service.


Code:
sysrc mysql_enable="YES"
service mysql-server start


Secure MariaDB installation.


Code:
mysql_secure_installation


Answer the question.

Enter current password for root (enter for none): ENTER
Switch to unix_socket authentication [Y/n] y
Change the root password? [Y/n] y
Remove anonymous users? [Y/n] y
Disallow root login remotely? [Y/n] y
Remove test database and access to it? [Y/n] y
Reload privilege tables now? [Y/n] y


as u can see,when he has installed mariadb,mysql57 has not been removed and it works for him. But not for me.

Code:
marietto@marietto:/usr/local/www/apache24/data # pkg install mariadb105-server mariadb105-client


Updating FreeBSD repository catalogue...
FreeBSD repository is up to date.
All repositories are up to date.
Checking integrity... done (3 conflicting)
  - mariadb105-server-10.5.15_3 conflicts with mysql57-server-5.7.38 on /usr/local/bin/innochecksum
  - mariadb105-client-10.5.15_3 conflicts with mysql57-client-5.7.38 on /usr/local/bin/mysql
  - mariadb105-client-10.5.15_3 conflicts with mysql57-server-5.7.38 on /usr/local/bin/mysqltest
Checking integrity... done (0 conflicting)
The following 4 package(s) will be affected (of 0 checked):

Installed packages to be REMOVED:
        mysql57-client: 5.7.38
        mysql57-server: 5.7.38

New packages to be INSTALLED:
        mariadb105-client: 10.5.15_3
        mariadb105-server: 10.5.15_3

Number of packages to be removed: 2
Number of packages to be installed: 2

The process will require 47 MiB more space.

Proceed with this action? [y/N]: y
[1/4] Deinstalling mysql57-client-5.7.38...
[1/4] Deleting files for mysql57-client-5.7.38: 100%
[2/4] Deinstalling mysql57-server-5.7.38...
[2/4] Deleting files for mysql57-server-5.7.38: 100%
==> You should manually remove the "mysql" user.
==> You should manually remove the "mysql" group
[3/4] Installing mariadb105-client-10.5.15_3...
===> Creating groups.
Using existing group 'mysql'.
===> Creating users
Using existing user 'mysql'.
===> Creating homedir(s)
[3/4] Extracting mariadb105-client-10.5.15_3: 100%
[4/4] Installing mariadb105-server-10.5.15_3...
===> Creating groups.
Using existing group 'mysql'.
===> Creating users
Using existing user 'mysql'.
===> Creating homedir(s)
[4/4] Extracting mariadb105-server-10.5.15_3: 100%
=====
Message from mariadb105-client-10.5.15_3:

--
MariaDB respects hier(7) and doesn't check /etc and /etc/mysql for my.cnf. Please move existing my.cnf files from those paths to
/usr/local/etc/mysql or /usr/local/etc. Sample configuration files are provided in /usr/local/etc/mysql and /usr/local/etc/mysql/conf.d.
The rc(8) script no longer uses /var/db/mysql/my.cnf for configuration nor /var/db/mysql for logs and PID-file.

This port does NOT include the mytop perl script, this is included in the MariaDB tarball but the most recent version can be found in the
databases/mytop port


=====
Message from mariadb105-server-10.5.15_3:

--
MariaDB respects hier(7) and doesn't check /etc and /etc/mysql for
my.cnf. Please move existing my.cnf files from those paths to
/usr/local/etc/mysql or /usr/local/etc. Sample
configuration files are provided in /usr/local/etc/mysql
and /usr/local/etc/mysql/conf.d.
The rc(8) script no longer uses /var/db/mysql/my.cnf for configuration
nor /var/db/mysql for logs and PID-file.

This port does NOT include the mytop perl script, this is included in
the MariaDB tarball but the most recent version can be found in the
databases/mytop port


marietto@marietto:/usr/local/www/apache24/data # sysrc mysql_enable="YES"
mysql_enable: yes -> YES


marietto@marietto:/usr/local/www/apache24/data # service mysql-server start
Starting mysql.


marietto@marietto:/usr/local/www/apache24/data # mysql_secure_installation

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user. If you've just installed MariaDB, and
haven't set the root password yet, you should just press enter here.

Enter current password for root (enter for none):
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysql/mysql.sock' (
2)
Enter current password for root (enter for none):
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysql/mysql.sock' (
2)
Enter current password for root (enter for none):
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysql/mysql.sock' (
2)
Enter current password for root (enter for none):
 
Is 127.0.0.1 a routable IP-address ?
It's not. That address is just a loopback to localhost.

ziomario : After re-installing the MySQL server (ditch MariaDB), you do need to double-check that a few things are in place:
  • /usr/local/etc/rc.conf needs the line mysqld_enable="YES". hbsd likely misspelled the command, and left out the 'd' part.
  • /usr/local/etc/mysql/my.cnf needs to exist, and be at least readable (with 444 perms)
  • user and group 'mysql' can be re-used, but they do need to exist.
  • If you start the service, e.g., with service mysql-server start, it needs to return a PID of a running process. If you don't get the PID of a running process at this point, you have a problem, the server daemon is not running, and nothing is gonna work.
  • /var/run/mysql/mysql.sock is a socket file created when the MySQL server is started. If the server is not started, the socket should not exist.
 
(mariadb is not installed) :

Code:
marietto@marietto:/usr/local/etc/mysql # cat /etc/passwd | grep mysql
mysql:*:88:88:MySQL Daemon:/var/db/mysql:/usr/sbin/nologin

marietto@marietto:/usr/local/etc/mysql # chmod 444 my.cnf

marietto@marietto:/usr/local/etc/mysql # service mysql-server onestart
Starting mysql.

marietto@marietto:/usr/local/etc/mysql # ps ax | grep mysql
69466  0  S+     0:00.00 grep mysql

what else ?
 
(mariadb is not installed) :

Code:
marietto@marietto:/usr/local/etc/mysql # cat /etc/passwd | grep mysql
mysql:*:88:88:MySQL Daemon:/var/db/mysql:/usr/sbin/nologin

marietto@marietto:/usr/local/etc/mysql # chmod 444 my.cnf

marietto@marietto:/usr/local/etc/mysql # service mysql-server onestart
Starting mysql.

marietto@marietto:/usr/local/etc/mysql # ps ax | grep mysql
69466  0  S+     0:00.00 grep mysql

what else ?
Check the status of mysql, make sure the server daemon is running.
 
I would recommend removing the contents of /var/db/mysql/ before starting MySQL for the first time. There's been so much mucking around with different versions now, I fear the actual database files have been thoroughly thrashed. And you're starting off with an 'empty' database anyway, there's no old data to preserve.
 
I would recommend removing the contents of /var/db/mysql/ before starting MySQL for the first time. There's been so much mucking around with different versions now, I fear the actual database files have been thoroughly thrashed. And you're starting off with an 'empty' database anyway, there's no old data to preserve.
I'm sure if he does that and does the installation again, the problem will be completely solved. This has happened to me over and over again and this is how I solved the problem. pkg does not remove all the files and some configurations remain. A number of remaining settings prevent MySQL or MariaDB from running.
 
Code:
marietto@marietto:/var/db # mv mysql mysql_

marietto@marietto:/var/db # pkg remove mariadb104-server 


Checking integrity... done (0 conflicting)
Deinstallation has been requested for the following 1 packages (of 0 packages in the universe):

Installed packages to be REMOVED:
mariadb104-server: 10.4.24_3

Number of packages to be removed: 1

The operation will free 214 MiB.

Proceed with deinstalling packages? [y/N]: y
[1/1] Deinstalling mariadb104-server-10.4.24_3...
[1/1] Deleting files for mariadb104-server-10.4.24_3: 100%
==> You should manually remove the "mysql" user. 
==> You should manually remove the "mysql" group
 
marietto@marietto:/var/db # service mysql-server start


mysql-server does not exist in /etc/rc.d or the local startup directories (/usr/local/etc/rc.d), or is not executable
 
ziomario
Remove MariaDB and MySQL packages with pkg and go to these directories
and remove all remaining files and folders with names that start with mariadb or mysql:

/usr/local/bin
/var/db
/tmp
/usr/local/etc
/usr/local/include
/usr/local/lib
/usr/local/libexec
/usr/local/share

And then decide whether you want to use MariaDB or MySQL and install only one of them. I know manually deleting files is tedious but it solves your problem.
 
Hip Hip Urra' for SirDice for the strike.

Code:
marietto@marietto:/var/db # pkg install mysql57-server

Updating FreeBSD repository catalogue...
FreeBSD repository is up to date.
All repositories are up to date.
Checking integrity... done (2 conflicting)
- mysql57-server-5.7.38 conflicts with mariadb104-client-10.4.24_3 on /usr/local/bin/replace
- mysql57-client-5.7.38 conflicts with mariadb104-client-10.4.24_3 on /usr/local/bin/mysql
Checking integrity... done (0 conflicting)
The following 3 package(s) will be affected (of 0 checked):

Installed packages to be REMOVED:
mariadb104-client: 10.4.24_3

New packages to be INSTALLED:
mysql57-client: 5.7.38
mysql57-server: 5.7.38

Number of packages to be removed: 1
Number of packages to be installed: 2

The process will require 155 MiB more space.

Proceed with this action? [y/N]: y
[1/3] Deinstalling mariadb104-client-10.4.24_3...
[1/3] Deleting files for mariadb104-client-10.4.24_3: 100%
[2/3] Installing mysql57-client-5.7.38...
[2/3] Extracting mysql57-client-5.7.38: 100%
[3/3] Installing mysql57-server-5.7.38...
===> Creating groups.
Using existing group 'mysql'.
===> Creating users
Using existing user 'mysql'.
===> Creating homedir(s)
[3/3] Extracting mysql57-server-5.7.38: 100%
=====
Message from mysql57-client-5.7.38:

--
This is the mysql CLIENT without the server.
for complete server and client, please install databases/mysql57-server
=====
Message from mysql57-server-5.7.38:

--
Initial password for first time use of MySQL is saved in $HOME/.mysql_secret
ie. when you want to use "mysql -u root -p" first you should see password
in /root/.mysql_secret

MySQL57 has a default /usr/local/etc/mysql/my.cnf,remember to replace it with your own or set `mysql_optfile="$YOUR_CNF_FILE` in rc.conf.


marietto@marietto:/var/db # service mysql-server start
Starting mysql.


marietto@marietto:/var/db # service mysql-server status
mysql is running as pid 8415.
 
Back
Top