Difference between revisions of "Test MySQL installation"
(→Test Source) |
(→Test Database) |
||
Line 14: | Line 14: | ||
Insert a couple of fields into the table. | Insert a couple of fields into the table. | ||
+ | |||
+ | Create - in '''Privileges''' - a new user. | ||
+ | |||
+ | Use the edit button at the end of the name in this view: | ||
+ | |||
+ | [[File:User.png|500 px]] | ||
+ | |||
+ | then click the '''Check ALL''' in the following | ||
+ | |||
+ | [[File:User1.png|500px]] | ||
+ | |||
+ | and finally the '''Go''' button to save the privileges. | ||
==Test Source== | ==Test Source== |
Revision as of 13:06, 21 January 2014
After installing the necessary development tools and the MySQL database (see Install essential development utilities) it is time for at quick test to see if everything works.
Test Database
In PHPMyAdmin create a new database called test
Create a new table in the test database. Create 3 fields. The fields shall be named:
id name place
The id field shall be of type int', 10 in length, unsigned attribute, Not Null, auto_increment, Primary
Insert a couple of fields into the table.
Create - in Privileges - a new user.
Use the edit button at the end of the name in this view:
then click the Check ALL in the following
and finally the Go button to save the privileges.
Test Source
Using Eclipse there are a couple of settings, that needs to be ensured.
In the project settings ensure that you have the correct paths for the compiler to search for include files:
and the correct paths to the libraries:
Enter the source below in a .c-file or .cpp-file:
/* Simple C program that connects to MySQL Database server*/ #include <mysql.h> #include <stdio.h> #include <stdlib.h> int main() { MYSQL *conn; MYSQL_RES *res; MYSQL_ROW row; char *server = "localhost"; char *user = "USERNAME"; char *password = "PASSWORD"; /* set me first */ char *database = "test"; conn = mysql_init(NULL); /* Connect to database */ if ( ! mysql_real_connect(conn, server, user, password, database, 0, NULL, 0)) { fprintf(stderr, "%s\n", mysql_error(conn)); exit(1); } /* send SQL query */ if (mysql_query(conn, "show tables")) { fprintf(stderr, "%s\n", mysql_error(conn)); exit(1); } res = mysql_use_result(conn); /* output table name */ printf("MySQL Tables in mysql database:\n"); while ((row = mysql_fetch_row(res)) != NULL) printf("%s \n", row[0]); /* close connection */ mysql_free_result(res); mysql_close(conn); }
Be sure to change the USERNAME and PASSWORD to a valid user on the database server.