I have just started using C# and do not know much about it. I am using the 3d game engine called Unity and trying to write a c# script to access the MySQL database that I am running. The MySQL database is on a different computer. My question is how can I access the MySQL database using C#. I know the username, password and database I want to use, but I can not figure out how to access the database.
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.
You can then add a new C source file and replace it with this content. Using the ODBC APIs SQLAllocHandle, SQLSetConnectAttr, and SQLDriverConnect, you should be able to initialize and establish a connection to your database.
To connect to the database server, confirm that the MySQL Database Server is running on your machine, right-click the Databases > MySQL Server node in the Services window and choose Connect. You might be prompted to supply a password to connect to the server.
1. Open the Command Prompt and navigate to the bin folder of your MySQL Server installation directory. Then connect to the server using the mysql -u root -p command. Enter the password and execute the SHOW DATABASES; command we have discussed above.
You will need to get the C# MySQL driver: http://dev.mysql.com/downloads/connector/net/
And then you will need to follow the MySQL manual for setting it up and using it. It's a standard ADO.NET driver, so you should be able to follow most any C# SQL tutorials out there for additional help.
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