I have a C# Application which would access a MySQL server on another computer. I am trying to do it via IP. Here is my Connection String :
server = "192.168.10.221";
database = "restaurantdb";
uid = "root";
password = "";
string connectionString;
connectionString = "SERVER=" + server + "; PORT = 3306 ;" + "DATABASE=" + database + ";" + "UID=" + uid + ";" + "PASSWORD=" + password + ";";
mycon = new MySqlConnection(connectionString);
Now the idea is, I would connect it through the Internet or Wi-Fi connection on which both of the computers are connected to. I would then access the database through SQL Strings coded on C#. Now I could also connect them through LAN networking but I don't know how.
I am getting this exception in my code
{"Access denied for user 'root'@'Crave-PC.lan' (using password: NO)"} System.Exception {MySql.Data.MySqlClient.MySqlException}
Any ideas how I can access the server through networking?
MySQL database is available on most important OS platforms. It runs on BSD Unix, Linux, Windows, or Mac OS. To be able to compile C examples, we need to install the MySQL C development libraries. The above line shows how we can do it on Debian based Linux.
via cPanel To add your computer as an Access Host: Log in to cPanel. Under the Databases section, click on the Remote MySQL® icon. On the Remote MySQL® page, enter the connecting IP address, then click Add Host.
The problem is at MySQL Server side, root user doesn't have permissions to connect remotelly. To give root user permisions to connect remotelly just type this on a mysql command line:
GRANT ALL PRIVILEGES ON *.* TO root@"%" IDENTIFIED BY 'rootPass';
Just change 'rootPass' for your current root password, if root doesnt have password MySQL wont let you connect so you will have to define one for it.
One side note: As a security best practice you should define a different user other than root to access your mysql databases from client applications.
Hope it helps,
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With