2

I'm trying to use MySQL on Arch Linux. it is already installed but this error comes up when I try to connect:

connect to server at 'localhost' failed
error: 'Can't connect to local MySQL server through socket '/run/mysqld/mysqld.sock' (2 "No such file or directory")'

I've looked for /etc/my.cfg but the file does not exist. Something must have gone wrong during the installation. How can I "purge" MariaDB and reinstall it?

Pedram
  • 921
  • 1
  • 10
  • 17
tino
  • 151
  • 3
  • 9

4 Answers4

2

If you're using archlinux it is a vital idea to understand the package manager (pacman). For the question about /etc/my.cfg you can run

pacman -Ql mariadb

there you will see that the file is actually called:

/etc/mysql/my.cnf

Arch linux will not configure the package for you, that is part of the arch philosophy. It will provide example configurations, and even provide you with a systemd unit file

usr/lib/systemd/system/mysqld.service

but it is your responsibility to ensure that the configuration is correct and actually start the daemon.

systemctl enable mysqld   # add the unit file to the boot sequence
systemctl start mysqld    # runs ExecStart= in the unit file
systemctl stop mysqld     # kills the daemon
systemctl disable mysqld  # remove unit from boot sequence

reinstall

Since the word reinstall is in the title of the question and someone might find this question thanks to that: To reinstall mariadb you simply do

pacman -S mariadb

pacman will reinstall a package that is already installed, there is no need to remove the package (for completeness, package removal happens with pacman -R)

grochmal
  • 2,901
  • 2
  • 22
  • 28
  • I know the basics commands of pacman, to install and remove. I tried to reinstall mariadb but the error is the same. The my.cfg file is in place. when i type systemctl status mysql i get "Loaded: not-found (Reason: No such file or directory)" – tino Jun 08 '16 at 07:31
  • @tino - you did not rename `my.cnf` to `my.cfg`, did you? – grochmal Jun 08 '16 at 18:44
2

as of 7-28-17 I had to do this on a new install. Newbie here might save someone some time. It was a real pain.

OK HERE IS THE DEAL!!!!! INSTALL APACHE _ NO PROB

INSTALL MYSQL _PROBLEM pacman -S mysql then before starting service

  1. MUST UNCOMMENT INNODB IN:

    nano /etc/mysql/my.cnf

  2. then must initialize datadirectory before starting service:

    mysql_install_db --user=mysql --basedir=/usr --datadir=/var/lib/mysql

You need to initialize the MariaDB data directory prior to starting the service. This can be done with mysql_install_db command, e.g.: mysql_install_db --user=mysql --basedir=/usr --datadir=/var/lib/mysql Optional dependencies for mariadb galera: for MariaDB cluster with Galera WSREP perl-dbd-mysql: for mysqlhotcopy, mysql_convert_table_format and mysql_setpermission

Rahul Khurana
  • 8,577
  • 7
  • 33
  • 60
steve
  • 21
  • 1
1

CNF file is /etc/mysql/my.cnf in Arch Linux.

One simple way I can reproduce your issue is when MariaDB is shut down. Sorry if it sounds dumb but as you did not mention it: is MariaDB started? sudo systemctl start mysqld.service

You should have a look at MariaDB logs to get some clue: journalctl _SYSTEMD_UNIT=mysqld.service (maybe paste some part if you still don't get what is going on).

galaux
  • 375
  • 2
  • 14
1

This happens the first time you install MySQL and MariaDB. As grochmal pointed out, you have to set up configurations before first use. But, the user teckk sent these three links in the archlinux newbie corner:

  1. https://wiki.archlinux.org/index.php/MariaDB
  2. https://wiki.archlinux.org/index.php/MariaDB#Reset_the_root_password
  3. https://bbs.archlinux.org/viewtopic.php?id=51981

In short, you have to run the command below before starting the service:

sudo mariadb-install-db --user=mysql --basedir=/usr --datadir=/var/lib/mysql

Optionally (recommended) you should improve the initial security by calling:

sudo mysql_secure_installation

Now you can start the service:

sudo systemctl start mariadb

Optionally, you could install and use a graphical front-end tool. Carry on with setting up the configurations as described in the archwiki post on MariaDB Configuration.

Pedram
  • 921
  • 1
  • 10
  • 17