ThanhLam112358
ThanhLam112358

Reputation: 916

How to connect mysql in 000webhost?

I create a free host in 000webhost. It is active, here is link http://rndsctvlab.hostei.com/.

info

Then I create database have information

 $mysql_host = "mysql10.000webhost.com";
 $mysql_database = "a9127803_data1";
 $mysql_user = "<username>";
 $mysql_password = "<password>";

Now I want to connect and add data to mysql on this host from my pc. I write a code in C# but it fail,

It warning

enter image description here

Here is my code

string myConnection = "Server=31.170.160.97;Database=a9127803_data1;   Port=3306;User ID=<username>;Password=<password>";
        conDatabase = new MySqlConnection(myConnection);
        string Query = "INSERT into ex1 (ID,Name,Address) values ('" + txt_ID.Text + "','" + txt_name.Text + "','" + txt_address.Text + "');";
        MySqlCommand cmdDataBase = new MySqlCommand(Query, conDatabase);
        MySqlDataReader myReader;
        try
        {
            conDatabase.Open();
            myReader = cmdDataBase.ExecuteReader();
            MessageBox.Show("SAVE");
            while (myReader.Read())
            {
            }
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }

How can I fix it? Thank you for help.

Upvotes: 3

Views: 5690

Answers (1)

SeanS
SeanS

Reputation: 428

I've had this problem before and found that I needed to allow user permissions from IP addresses on MySQL 5 databases.

So for example, if you use MySQL Workbench or MySQL Query Broswer, the query would be like this to allow all hosts:

GRANT ALL ON a9127803_data1.* TO 'a9127803_data2'@'YourIpAddress';

Not quite sure how 000webhost works, or if you can do queries from there, but the above MySQL query is what helped me. You can customise it for each database and user.

EDIT: Should you need to customise the permissions, look at this MySQL link for more examples using the GRANT syntax

EDIT 2: If you need to grant permissions via command line, here is an example:

cd C:\mysql //push to your MySQL directory on your server
.\bin\mysql -u user -p
//Enter Password now

grant all on YourDb.YourDbTable to YourUser@YourIpAddress;

Once you enter this, it should grant the permissions for your user on the IP address of your choosing, for the database and table selected.

Upvotes: 1

Related Questions