Click here to Skip to main content
15,867,771 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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
C#
<add key="con" value="Server=localhost;User ID=*****;Password=*******;Database=net;port=3307;Pooling=false"/>


C#
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: 2.10.8.1 (Debian 2.10.8.1-5); ASP.NET Version: 2.0.50727.1433
Posted

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,
 
Share this answer
 
Please refer to this it may help you

http://forums.mysql.com/read.php?38,596567,596581#msg-596581[^]
 
Share this answer
 
Comments
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    
how?
The most likely cause of this is that MySQL is not configured to accept tcp/ip connections.
See here http://dev.mysql.com/doc/mysql/en/can-not-connect-to-server.html
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
 
Share this answer
 
Comments
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
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html

# 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.
[client]
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.
[mysqld_safe]
socket = /var/run/mysqld/mysqld.sock
nice = 0

[mysqld]
#
# * Basic Settings
#
user = mysql
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
port = 3307
basedir = /usr
datadir = /var/lib/mysql
tmpdir = /tmp
language = /usr/share/mysql/english
#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
#
# * 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
wait_timeout=10
#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
#log-queries-not-using-indexes
#
# 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_file_per_table
innodb_log_buffer_size=4M
innodb_flush_log_at_trx_commit=2
innodb_thread_concurrency=8
innodb_buffer_pool_size=8G
# 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



[mysqldump]
quick
quote-names
max_allowed_packet = 16M

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

[isamchk]
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/
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
ex
SQL
server = 192.168.1.1


on server
- change bind-ipaddress = ipOfServer
ex
SQL
bind-ipaddress = 192.168.1.1

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

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



the last line is very important, i hope this help
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900