Please whitelist cPanel in your adblocker so that you’re able to see our version release promotions, thanks!

The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Unable to connect to my mysql database

Discussion in 'Database Discussions' started by alandioda, Oct 8, 2017.

  1. alandioda

    alandioda Registered

    Joined:
    Oct 8, 2017
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    Slovenia
    cPanel Access Level:
    Website Owner
    Hello, I want to connect to MySQL database, but it doesn't want to connect.

    I have bought Web Hosting and domain name at Truehoster.
    I connected to cPanel and made the following things:
    - I created a new database
    - I created a user with all privileges
    - I went to Remote MySQL and added my IP

    I tried to connect with many programs and applications but was unsuccessful.

    I have a c# script for testing. The code is here if you need it but it works because I had no problems to connect with my program to one of free MySQL database from freemysqlhosting.

    I get this error when I use my database from Truehoster:
    Or in some programs or applications, it is just connecting forever.
    I'm pretty sure I put the correct database name, username, and password.

    My C# program:
    Code:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using MySql.Data;
    
    namespace ConsoleApplication1
    {
        class Program
        {
            static void Main(string[] args)
            {
                string serverIp = "ns111.truehoster.net";
                string databaseName = "my-database-name";
                string username = "user";
                string password = "password";
    
                string createTableQuery = string.Format(@"CREATE TABLE `{0}` (
                   `sid` smallint(5) unsigned NOT NULL AUTO_INCREMENT,
                   `name` varchar(120) NOT NULL DEFAULT '',
                   `title` varchar(120) NOT NULL DEFAULT '',
                   `description` text NOT NULL,
                   `optionscode` text NOT NULL,
                   `value` text NOT NULL,
                   `disporder` smallint(5) unsigned NOT NULL DEFAULT '0',
                   `gid` smallint(5) unsigned NOT NULL DEFAULT '0',
                   `isdefault` tinyint(1) NOT NULL DEFAULT '0',
                   PRIMARY KEY (`sid`),
                   KEY `gid` (`gid`))
                   ENGINE = MyISAM AUTO_INCREMENT = 1 DEFAULT CHARSET = utf8;", "TestTable1");
     
                string dbConnectionString = string.Format("server={0};uid={1};pwd={2};database={3};", serverIp, username, password, databaseName);
    
                try
                {
                    MySql.Data.MySqlClient.MySqlConnection conn = new MySql.Data.MySqlClient.MySqlConnection(dbConnectionString);
                    conn.Open();
    
                    var cmd = new MySql.Data.MySqlClient.MySqlCommand(createTableQuery, conn);
                    cmd.ExecuteNonQuery();
    
                    Console.WriteLine("done");
                }
                catch (Exception)
                {
                    Console.WriteLine("nope");
                    throw;
                }
                Console.ReadKey();
            }
    
        }
    }
    If this helps when I put some random host, for example, ns111.truehoster.com it gives me this error(2), but if I put incorrect username and or password It doesn't change anything (it shows the first error).

    Error(2):
    I'm really confused about this problem and don't know what I'm doing wrong.
    So I would be really grateful for any help.
     
  2. dalem

    dalem Well-Known Member
    PartnerNOC

    Joined:
    Oct 24, 2003
    Messages:
    2,615
    Likes Received:
    51
    Trophy Points:
    203
    Location:
    SLC
    cPanel Access Level:
    DataCenter Provider
    you are going to need to contact your provider
    Note: most providers block remote mysql connections for obvious security reasons
     
  3. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    38,658
    Likes Received:
    1,425
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    Hello,

    The previous post is correct. This is something you should report to your web hosting provider, as it's possible they have firewall rules blocking external connections to the MySQL service.

    Thank you.
     
Loading...

Share This Page