When I type in mysql
into terminal I got the following error:
ERROR 2002 (HY000): Can't connect to local server through socket '/run/mysqld/mysqld.sock' (2)
But if run mysql with some arguments like below:
mysql -h 127.0.0.1 -P 3306 -u root -p
It asked me the mysql password that is already defined in /etc/my.cnf . So I pasted the same password and I got connected to the database terminal like this:
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 4
Server version: 10.6.4-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
In my /etc/my.cnf
I have the following content:
[mysqld]
bind-address=127.0.0.1
port=3360
max_allowed_packet=64M
local-infile=0
innodb_file_per_table
[client]
user=root
password=MYSQLPASSWORDHERE
socket=/usr/local/mysql/data/mysql.sock
The question is, since I already have predefined root password, port and bind-address in /etc/my.cnf
, why does it still show error about socket if I run mysql
command without any arguments
My aim is to run mysql
command in terminal without any argument and it will present me the mysql terminal