Connecting to mysql doesn't work - mysql

I am trying to setup iRedMail but during the installation process I get this error:
ERROR 2003 (HY000): Can't connect to MySQL server on '127.0.0.1' (111)
and by default iRedMail tries to connect to MySql with TCP and not with a system socket.
To narrow down the problem, the following works:
mysql -h localhost -P 3306 -u root -p
but this does not
mysql -h 127.0.0.1 -P 3306 -u root -p
ERROR 2003 (HY000): Can't connect to MySQL server on '127.0.0.1' (111)
I am using mysql Ver 14.14 on Ubuntu 14.04
Here are the relevant configuration lines of /etc/mysql/my.cnf:
skip-networking=0
bind-address = 127.0.0.1
Also, mysql> SHOW VARIABLES; shows that
skip_networking | ON
Here are the relevant lines of px aux | grep mysql:
mysql /usr/sbin/mysqld --basedir=/usr --datadir=/mnt/storage/data/mysql/ --plugin- dir=/usr/lib/mysql/plugin --user=mysql --log-error=/var/log/mysql/error.log --pid-file=/var/run/mysqld/mysqld.pid --socket=/var/run/mysqld/mysqld.sock --port=3306
= EDIT =
The main question here is how to turn off skip_networking

Check your Firewall.
Or use Socket connection.

start mysql service then try
sudo service mysqld start
for installation of mysql in ubuntu
sudo apt-get install mysql-server mysql-client

It looks like you are using skip-networking and bind-address at the same time. You should never do this.
skip-networking disables TCP/IP - so just remove it.
bind-address means you are using TCP/IP.

Related

MySQL not running in my ubuntu terminal on windows 10. How to fix it?

I try running command ~$ mysql -u root -p
But the following error comes along-ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (13)
I have already installed mysql-client and mysql-server.Even it is not working
Start deamon sudo systemctl start mysql or run mysql -u root -p as root

Connecting to MariaDB via TCP returns socket error

I'm trying to connect to a local installation of MariaDB 10xx via the mysql command line application but despite specifying a host and a port I get an error the client cannot connect via the unix socket.
This is my my.cnf:
⟩ sudo vi /opt/local/etc/mariadb-10.1/my.cnf
# Use default MacPorts settings
!include /opt/local/etc/mariadb-10.1/macports-default.cnf
[mysqld]
socket=/private/tmp/mysqld.sock
port=3306
log_error=/private/tmp/mysql_error.log
log_warnings=3
general-log
general-log-file=/private/tmp/mariadb_queries.log
log-output=file
This is the command line I use:
mysql -u root --host localhost --port 3306 --password
And this is the error:
⟩ mysql -u root --host localhost --port 3306 --password
Enter password:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/opt/local/var/run/mariadb-10.1/mysqld.sock' (2 "No such file or directory")
I'm trying to check whether MariaDB is listening to TCP connections.
So I asked in the MariaDB IRC channel and apparently passing localhost to MariaDB causes it to use the unix socket. Replacing --host localhost with --host 127.0.0.1 did the trick.

Granting remote access to MySQL database

I am trying to grant remote access to a mysql database. However I think I am missing a step somewhere.
Server is a VM - Ubuntu 12.04.5 - inet addr:134.226.38.147
mysql Ver 14.14 Distrib 5.5.38, for debian-linux-gnu (x86_64) using readline 6.2
Firstly I create the database on the remote server. I then grant wildcard access to all databases and tables for the user brendan. By using '%' I should have no problem connecting from my computer in college.
mysql> CREATE DATABASE foo;
mysql> GRANT ALL ON *.* TO 'brendan'#'%' IDENTIFIED BY 'mypassword';
I then open the port using
iptables -A INPUT -p tcp -m tcp --dport 3306 -j ACCEPT
iptables-save | tee /etc/sysconfig/iptables
From what I read the above should work, however when I try to test the connection from my desktop this is what I get
localhost:~ brendan$ mysql -u brendan -h 134.226.38.147 -p
Enter password:
ERROR 2003 (HY000): Can't connect to MySQL server on '134.226.38.147' (61)
localhost:~ brendan$
or
localhost:~ brendan$ echo X | telnet -e X 134.226.38.147 3306
Telnet escape character is 'X'.
Trying 134.226.38.147...
telnet: connect to address 134.226.38.147: Connection refused
telnet: Unable to connect to remote host
localhost:~ brendan$
What am I missing?
Any help is much appreciated.
EDIT
my.cnf
I was unsure If I should comment out the bind-address = 127.0.0.1 which was already there
[mysqld]
#
# * Basic Settings
#
user = mysql
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
port = 3306
basedir = /usr
datadir = /var/lib/mysql
tmpdir = /tmp
lc-messages-dir = /usr/share/mysql
skip-external-locking
#
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
bind-address = 127.0.0.1
# ---- You added the below line ----------
bind-address = 134.226.38.147
I then restart with
sudo service mysql restart
Open your my.cnf file:
sudo vim /etc/mysql/my.cnf
Comment out the bind-address in your my.cnf.
like so: #bind-address = 127.0.0.1
Then restart mysql server so that the changes to the my.cnf file will take affect.
sudo service mysql restart
or
sudo /etc/init.d/mysql restart
You can read more here at DigitalOcean or rtcamp.
Now, a user will be able to connect to the Mysql database server remotely as long as they have proper user credentials.

Connecting to MySQL through Cygwin

I have XAMPP running on my desktop and can connect to the MySQL server via phpMyAdmin. However, when I try to connect through Cygwin:
Error: Can't connect to local MySQL server through socket '/var/run/mysql.sock' (2)
I've tried connecting to MySQL on the same machine, my local dev server and my remote server, all failed.
mysql -h 127.0.0.1 -P <PORT> -u root -p
This is what worked for me. Make sure you check what is the correct port.
Check the mysqld PID with:
ps -sW | grep mysqld
And then find the PORT with:
netstat -nao | grep <PID>
Have fun!
you can also add the alias of itself.
alias mysql = 'mysql -u {user} -p{password} -h 127.0.0.1'

want to change password for mysql root, but got error

I install Mysql5 using macports. But when trying to create password for the root account, I got this error:
sh-3.2# /opt/local/lib/mysql5/bin/mysqladmin -u root password 123456
/opt/local/lib/mysql5/bin/mysqladmin: connect to server at 'localhost' failed
error: 'Can't connect to local MySQL server through socket '/opt/local/var/run/mysql5/mysqld.sock' (61)'
Check that mysqld is running and that the socket: '/opt/local/var/run/mysql5/mysqld.sock' exists!
How to fix this?
Check to see if the mysql daemon is running
ps aux | grep mysqld
If it is you should see something like:
mysql 28290 1.1 2.7 340496 56812 ? Sl Jul31 348:27 /usr/libexec/mysqld --defaults-file=/etc/my.cnf --basedir=/usr --datadir=/var/lib/mysql --user=mysql --pid-file=/var/run/mysqld/mysqld.pid --skip-locking --socket=/var/lib/mysql/mysql.sock
If you are lucky you will see the --socket argument specifying exactly where your socket file is located. If it is somewhere different than the path your mysql client is looking for (/opt/local/var/run/mysql5/mysqld.sock), then you can specify it manually as one of the command line arguments.
Also, you should check to see if /etc/my.cnf exists and is setup properly, here is an example my.cnf:
[mysqld]
user=mysql_owner
datadir=/path/to/datadir/mysql
socket=/path/to/datadir/mysql/mysql.sock
skip-innodb
[mysql.server]
user=mysql_owner
basedir=/path/to/datadir
[client]
user=mysql_owner
socket=/path/to/datadir/mysql/mysql.sock
[safe_mysqld]
err-log=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
Hope this helps, fire away with questions if you are still having issues
Check what is the default socket for your distribution. You can also try connectiong on TCP4 using:
/opt/local/lib/mysql5/bin/mysqladmin -h 127.0.0.1 -u root -p secret
Or if you have found the path to your socket (in mysql's config file) you can use somthing like:
/opt/local/lib/mysql5/bin/mysqladmin --socket=/tmp/mysql.sock -u root -p secret