[SOLVED] mysql connect to server at 'localhost' failed
Linux - ServerThis forum is for the discussion of Linux Software used in a server related context.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Hello,
I've VPS with Debian 6 and imscp control panel ,
after uploaded my WordPress site and DB,
got this Error establishing a database connection
i did Google it to fix the error and following this guide [[ http://www.debianhelp.co.uk/mysql.htm]]To give localhost permission to access all databases
got this error
mysql: connect to server at 'localhost' failed
please,how can i fix this issues with my sql connections
If running and on default port 3306 lets try to connect
Code:
mysql -u root -p
as the user root and have us prompt for the password.
If that still gives the error try with the host option for mysql
Code:
mysql -h 127.0.0.1 -u root -p
or
Code:
mysql -h localhost -u root -p
or some other ip you have mysql running on. See the output of netstat.
If that all goes to now avail try to restart mysql without privileges and give the output of the mysql.user table to see how the permissions are set. or just reset them following the tut you linked.
Code:
service mysql stop
/usr/sbin/mysqld --skip-grant-tables
That stops mysql and restarts without any access restrictions.
If running and on default port 3306 lets try to connect
Code:
mysql -u root -p
as the user root and have us prompt for the password.
If that still gives the error try with the host option for mysql
Code:
mysql -h 127.0.0.1 -u root -p
or
Code:
mysql -h localhost -u root -p
or some other ip you have mysql running on. See the output of netstat.
If that all goes to now avail try to restart mysql without privileges and give the output of the mysql.user table to see how the permissions are set. or just reset them following the tut you linked.
Code:
service mysql stop
/usr/sbin/mysqld --skip-grant-tables
That stops mysql and restarts without any access restrictions.
Good mysql is up and running. How do you actually connect? Through the iscp admin panel or from a shell?
Are you doing this on the machine itself or from a remote host?
To help you further please include output of the shell or other error message into code blocks. (the button with the # on it).
Good mysql is up and running. How do you actually connect? Through the iscp admin panel or from a shell?
Are you doing this on the machine itself or from a remote host?
To help you further please include output of the shell or other error message into code blocks. (the button with the # on it).
I did this from shell and the machine itself.
via imscp connect with phpmyadmin,when browse the site ,got this error
( Error establishing a database connection )please where is the error.
phpmyadmin is on the same server? If not then you are note able to connect cause mysqld is not listening to a network address.
Lets first get the connection from the shell up and running. As the root user please do the following and copy and paste the output from the shell
Code:
mysql -p
first of all, thank you for your help.
i had many issues,
-telnet down
-cannot connect mysql
-when go to add domain ,i was delete it before, got [[Domain with that name already exists on the system.]]
please how can i fix these errors.
output
Code:
# mysql -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1862
Server version: 5.1.66-0+squeeze1 (Debian)
Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
i tried to connect mysql with ,
localhost
localhost:3306
local host
127.0.0.1
127.0.0.1:3306
localhost.mydomain.com
mysql.mydomain.com
sql.mydomain.com
and run this script (dbtest.php)
got , Unknown MySQL server host '#server4.mydomain.com.local' (1)
PS i'm able to connect phpmyadmin smoothly.
This post got quite big. Just read it once and then go through it step by step. We are getting there. Do not despair
Quote:
Originally Posted by Horus1
-telnet down
Telnet is deprecated. Please stop using it. Use SSH which encrypts traffic going over the network. Makes things more secure
Quote:
Originally Posted by Horus1
-cannot connect mysql
We have that one sorted out. The output you gave indicates that you can connect using the shell on the host the mysqld service resides. You can tell from the promtp
Code:
mysql>
You had been there before. I just not did get it right.
Quote:
Originally Posted by Horus1
-when go to add domain ,i was delete it before, got [[Domain with that name already exists on the system.]]
I guess this is through imscp. And as the message indicates the domain already exists. See if you can get a list of all configured domains within imscp. And also try if you can resolve this using the dig, nslookup or host command. Depending which one is available.
Quote:
Originally Posted by Horus1
Code:
# mysql -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1862
Server version: 5.1.66-0+squeeze1 (Debian)
Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
This one show that you are able to connect to mysql. Do a "Show database" and have a list of all the available domains. At least mysql should show up. This one is used for internals of mysqld.
Quote:
Originally Posted by Horus1
i tried to connect mysql with ,
localhost
localhost:3306
local host
127.0.0.1
127.0.0.1:3306
localhost.mydomain.com
mysql.mydomain.com
sql.mydomain.com
and run this script (dbtest.php)
The reason why not one of this could work is that mysqld is listening through socket. Also I think mysql client program uses the default socket path if 127.0.0.1 or localhost is used. But that might be distribution specific.
Quote:
Originally Posted by Horus1
got , Unknown MySQL server host '#server4.mydomain.com.local' (1)
PS i'm able to connect phpmyadmin smoothly.
Is phpmyadmin running on the same host as the mysqld service? I guess so. phpmyadmin normaly tries socket first, than localhost then the hostname.
Okay next should be the hostname and connection through this.
For this to work we first have to check that the domain is resolved by DNS. please make sure that the settings within the panel has the right collation between the name of the host and an ip that is on a network side interface (eth0 I'd say). If that one is good. try ping the host with the name. If the ping goes through we can get mysql to listen on that IP.
Change the option of bind-address inside /etc/mysql/my.cnf or through the panel. Use the outward facing IP or the hostname we configured before.
Okay next should be the hostname and connection through this.
For this to work we first have to check that the domain is resolved by DNS. please make sure that the settings within the panel has the right collation between the name of the host and an ip that is on a network side interface (eth0 I'd say). If that one is good. try ping the host with the name. If the ping goes through we can get mysql to listen on that IP.
please post the content of /etc/hosts. That might clear somethings. What also helps is to know if you are only working on the machine itself, over the panel, from remote host or all together? Please state that with most of the output of the command your using.
please post the content of /etc/hosts. That might clear somethings. What also helps is to know if you are only working on the machine itself, over the panel, from remote host or all together? Please state that with most of the output of the command your using.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.