MySQL Database Development Technology in Linux

Source: Internet
Author: User

First, you can download the latest version of the software free of charge after registering at www.hughes.com. au.MySQLThe installation is quite simple. The installation of the binary version (for software compiled on a hardware platform) only expands the file to a directory of the user and then configures several parameters. For example, the file you downloaded is: MySQL-2.0.3.tar.gz,
To install msql in the/usr/local directory, copy the file to the/usr/local directory, and then type the command tar zxvf.
MySQL-2.0.3.tar.gz, which expands the compressed file. Generally, all files in the MySQL database system are installed in the/usr/local/Hughes object.
Directory. The next step is to configure the MySQL database. All you need to do is modify the file msql. conf in the/usr/local/Hughes directory.

Mysql-user is the most widely used tool in practical applications.
And Admin-user. Mysql-user indicates the user who runs the MySQL database service program, while admin-user indicates that
Users who perform privileged operations (such as shutting down the running of database service programs and creating databases. Therefore, if you want the MySQL service program
User (s) running, specifying that the admin user can perform database operations. You need to change the rows of MySQL-user and admin-user to: mysql-user =
Database and admin-user =
Admin. In addition, you must change the owner of the files and directories under the Hughes directory to the database. After the configuration is complete, unregister the identity of the current user and re-use the msql. conf
Log on to the system as set by the mysql-user parameter. Enter the/usr/local/Hughes/bin directory and enter the following command:./msql2d
&, So that the MySQL database system is started. For the installation software with source code, you can check the README and install files to complete the installation.

To integrate MySQL into your applications, the MySQL database system provides you with a C Language
Api library and an interpreter: w3-msql, through the C language api library, you can integrate MySQL into applications developed with standard C language. With the w3-msql
You can embed an msql database into an HTML file by writing a C-like scripting language. The following is an example of a program.

The following program snippet is used to compare the user name and password submitted on the browser page with the user name and password in the registered-User table. If the user name and password are correct, the successful registration information is displayed on the page. Otherwise, the user registration fails. The method implemented in C language is as follows:

Void main (INT argc, char argv [])
{
// Parse the user name and password submitted by the user and save it to the username and password-USR variables.
...
// Create a socket with the local msql Database System
Sock = msqlconnect (null );
// Select database Test
If (msqlselectdb (sock, "test") =-1)
{
// Output database selection Failure Information
...
} Else
{
Sprintf (buff, "Select ?? From registered-user where username = '% S' ", username );
// Query records in the registered-User table with Username
If (msqlquery (sock, buff) =-1)
{
// Output the query failure error message
...
}
// Save the query result to the M-result type pointer variable res
Res = msqlstoreresult ();
// Obtain the number of records in the query result
Numrow = msqlnumrows (RES );
If (numrow = 1)
{
// Obtain the current record; Type: m_row
Row = msqlfetchrow (RES );
// Compare the password stored in the table with the password entered by the user
If (! Strcmp (password_ur, row [2])
{
// Output registration success Information
} Else
{
// Output prompt information with incorrect password
}
} Else
{
// Output error message for username Input
}
}
// Release the query result pointer
Msqlfreeresult (RES );
// Close the socket of the Database System
Msqlclose (sock );
Return;
}

The above example contains the main functions used to integrate MySQL into a C language program. These functions can basically meet the needs of applications. If the use of w3-msql can be interpreted Class C language embedded into HTML files, can achieve the same function. Different from the cgi program compiled in C language, the script language does not need to be compiled. The script is interpreted and executed by the CGI program w3-msql provided by the MySQL database system. The main code segment in the script is as follows:

<HTML> 〉
<Head> 〉
<Meta HTTP-EQUIV = "Content-Type" content = "text/html; charset = iso-8859-1"> ″〉
</Head> 〉
<Body text = "#000000" background = "/icon/back.jpg" topmargin = "10"> ″〉
<〈!
// Parse the user name and password submitted by the user and
Save to the username and password-USR Variables
...
// Create a socket with the local msql Database System
$ Sock = msqlconnect ();
// Select database Test
If (msqlselectdb ($ sock, "test") =-1)
{
// Output database selection Failure Information
Fatal ("error: Unable to connect to Database ″);
} Else
{
$ Buff = "Select ?? From registered-user where username = '$ Username ′″;
// Query records in the registered-User table with Username
If (msqlquery ($ sock, $ buff) =-1)
{
// Output the query failure error message
Fatal ("query error N ″);
}
// Save the query result to res, the pointer variable of the query result.
$ Res = msqlstoreresult ();
// Obtain the number of records in the query result
$ Numrow = msqlnumrows ($ res );
If ($ numrow = 1)
{
// Get the pointer of the current record
$ ROW = msqlfetchrow ($ res );
// Compare the password stored in the table with the password entered by the user
If (! Strcmp ($ password-Ur, $ row [2])
{
// Output registration success Information
Echo ("center> registered successfully </center> 〉″);
} Else
{
// Output prompt information with incorrect password
Echo ("center> the password you entered is incorrect </center> 〉″);
}
} Else
{
// Output error message for username Input
Echo ("center> the user name you entered is incorrect </center> 〉″);
}
}
// Release the memory occupied by query results
Msqlfreeresult ($ res );
// Close the socket of the Database System
Msqlclose ($ sock );
> 〉
</Body> 〉
</Html> 〉

The above describes how to develop an application system using the MySQL database system as the background database in Linux. With these basic methods, we can develop various msql database-based application systems.

ZZ: http://blog.csdn.net/onlyzhangqin/archive/2008/09/02/2867164.aspx

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.