Click here to Skip to main content
14,426,057 members
Rate this:
Please Sign up or sign in to vote.
i am trying to Connect to MySQL server on Debian from application hosted on server itself.I try everything change bind address many times and restart MySQL server.changes CS from IP Address to local host does not work.MySQL server on Linux is connecting to any windows machine through IP Address Smoothly. Pls Help me.Thanks In Advance.......
My connection string is
<add key="con" value="Server=localhost;User ID=*****;Password=*******;Database=net;port=3307;Pooling=false"/>

Server Error in '/' Application

Unable to connect to any of the specified MySQL hosts.

Description: HTTP 500. Error processing request.

Stack Trace:

MySql.Data.MySqlClient.MySqlException: Unable to connect to any of the specified MySQL hosts.
  at MySql.Data.MySqlClient.NativeDriver.Open () [0x00000] in <filename unknown>:0 
  at MySql.Data.MySqlClient.Driver.Open () [0x00000] in <filename unknown>:0 
  at MySql.Data.MySqlClient.Driver.Create (MySql.Data.MySqlClient.MySqlConnectionStringBuilder settings) [0x00000] in <filename unknown>:0 
  at MySql.Data.MySqlClient.MySqlConnection.Open () [0x00000] in <filename unknown>:0 
Version information: Mono Runtime Version: (Debian; ASP.NET Version: 2.0.50727.1433
Rate this:
Please Sign up or sign in to vote.

Solution 2

The error you are getting indicates it can't resolve the host name which is a dns issue. Whatever the server name in your connection string is, the name cannot be reolved. If the database is on the same machine as the web server you can use localhost for the server name, if its on a different machine you can try to ping it by name and it will probably give you the same error if it can't resolve the name. If you know the ip address of the machine with MySQL, you can edit your hosts file and add a row like

192.168.0.x hostname

using whatever the ip address and host name are for the MySQL machine and that will resolve the host name to the ip address

On windows your hosts file should be in Windows\System32\Drivers\etc folder

You may also get an error if the MySQL machine is not configured to allow tcp/ip connections but the error you are getting now is clearly a DNS error.

What version of MySQL are you using and what did you have to edit? I've never had any errors running the scripts for MySQL so it makes me think you are using a very old version of MySQL.

Also please note whether you are using the release files or working with the source code

Hope it helps,
Rate this:
Please Sign up or sign in to vote.

Solution 1

Please refer to this it may help you,596567,596581#msg-596581[^]
pankajgarg1986 17-Feb-14 5:08am
MySQL server is accessible through Workbench using remote host.But Application can not to it.
[no name] 17-Feb-14 5:16am
Check whether the General Configurations Like Host name is 'localhost ' not any other name and the user name and password are correct and the user has permission to check the DB.
TatsuSheva 27-Oct-16 10:05am
Rate this:
Please Sign up or sign in to vote.

Solution 3

The most likely cause of this is that MySQL is not configured to accept tcp/ip connections.
See here
make sure your /etc/mysql/my.conf file does not have the "skip-networking" feature enabled. This is the default in some installations and disables tcp/ip connections.

Hope it helps,

If not resolved let me know will try with some other way
pankajgarg1986 17-Feb-14 6:35am
It problem only from local host on same machine And its working fine from any host.But giving IP Address not solve my problem from same machine..
Here is My my.conf file pls check and let me know aany chaned any it.
# The MySQL database server configuration file.
# You can copy this to one of:
# - "/etc/mysql/my.cnf" to set global options,
# - "~/.my.cnf" to set user-specific options.
# One can use all long options that the program supports.
# Run program with --help to get a list of available options and with
# --print-defaults to see which it would actually understand and use.
# For explanations see

# This will be passed to all mysql clients
# It has been reported that passwords should be enclosed with ticks/quotes
# escpecially if they contain "#" chars...
# Remember to edit /etc/mysql/debian.cnf when changing the socket location.
port = 3307
socket = /var/run/mysqld/mysqld.sock
# Here is entries for some specific programs
# The following values assume you have at least 32M ram

# This was formally known as [safe_mysqld]. Both versions are currently parsed.
socket = /var/run/mysqld/mysqld.sock
nice = 0

# * Basic Settings
user = mysql
pid-file = /var/run/mysqld/
socket = /var/run/mysqld/mysqld.sock
port = 3307
basedir = /usr
datadir = /var/lib/mysql
tmpdir = /tmp
language = /usr/share/mysql/english
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
#bind-address =
# * Fine Tuning
key_buffer = 256M
max_allowed_packet = 16M
thread_stack = 192K
thread_cache_size = 8
# This replaces the startup script and checks MyISAM tables if needed
# the first time they are touched
myisam-recover = BACKUP
max_connections = 2000
#table_cache = 64
#thread_concurrency = 10
# * Query Cache Configuration
query_cache_limit = 2M
query_cache_size = 1024M
# * Logging and Replication
# Both location gets rotated by the cronjob.
# Be aware that this log type is a performance killer.
# As of 5.1 you can enable the log at runtime!
#general_log_file = /var/log/mysql/mysql.log
#general_log = 1
# Error logging goes to syslog due to /etc/mysql/conf.d/mysqld_safe_syslog.cnf.
# Here you can see queries with especially long duration
#log_slow_queries = /var/log/mysql/mysql-slow.log
#long_query_time = 2
# The following can be used as easy to replay backup logs or for replication.
# note: if you are setting up a replication slave, see README.Debian about
# other settings you may need to change.
server-id = 5
log_bin = /var/log/mysql/mysql-bin.log
expire_logs_days = 30
#max_binlog_size = 100M
#binlog_do_db = pos
#binlog_ignore_db = include_database_name
# * InnoDB
# InnoDB is enabled by default with a 10MB datafile in /var/lib/mysql/.
# Read the manual for more InnoDB related options. There are many!
# * Security Features
# Read the manual, too, if you want chroot!
# chroot = /var/lib/mysql/
# For generating SSL certificates I recommend the OpenSSL GUI "tinyca".
# ssl-ca=/etc/mysql/cacert.pem
# ssl-cert=/etc/mysql/server-cert.pem
# ssl-key=/etc/mysql/server-key.pem

max_allowed_packet = 16M

#no-auto-rehash # faster start of mysql but no tab completition

key_buffer = 16M

# * IMPORTANT: Additional settings that can override those from this file!
# The files must end with '.cnf', otherwise they'll be ignored.
!includedir /etc/mysql/conf.d/
Rate this:
Please Sign up or sign in to vote.

Solution 4

this is work for me.

- try your code with mysql server on localhost
if it works fine then try connect to mysql server on real server.

with :
on your code
``- change server = localhost to server = ipOfServer
server =

on server
- change bind-ipaddress = ipOfServer
bind-ipaddress =

- create user on mysql like this
GRANT ALL ON nameOfDatabase.* TO nameOfUser@'ipOfYourClient' IDENTIFIED BY 'xxx';

GRANT ALL ON myDb.* TO myName@'' IDENTIFIED BY 'xxx';

the last line is very important, i hope this help

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100