MySQL installation on Windows and VC connection to MySQL database through ODBC

Source: Internet
Author: User
Tags stored procedure example mysql gui mysql gui tools mysql odbc driver

 

I,MySQLInstallation

1,

Http://dev.mysql.com/downloads/mysql/5.0.html

2. download content

(1)mysql-noinstall-5.0.45-win32.zip

(2)mysql-gui-tools-noinstall-5.0-r12-win32.zip

(3366mysql-connector-odbc-noinstall-3.51.21-win32.zip

3. Installation Steps

3.1 install the MySQL Service

(1) Create My. ini with the following content. Put the file in the Windows folder of the System Disk:

[Winmysqladmin]

Server = D:/MySQL-DB/mysql-5.0.45-win32/bin/mysqld-nt.exe

[MySQL]

Default-character-set = utf8

[Client]
Default-character-set = utf8

[Mysqld]
Default-character-set = utf8

Basedir = D:/MySQL-DB/mysql-5.0.45-win32

Datadir = D:/MySQL-DB/mysql-5.0.45-win32/Data

Basedir is the installation directory.

(2) Open the MS-DOS window, switch to the "D:/MySQL-DB/mysql-5.0.45-win32/bin" Directory; or put "D: add/MySQL-DB/mysql-5.0.45-win32/bin to the PATH variable of environment variable. Execute the following command:

Mysqld-NT-install

(3) start and stop the MySQL Service

D:/MySQL-DB/mysql-5.0.45-win32/bin> Net start MySQL

D:/MySQL-DB/mysql-5.0.45-win32/bin> net stop MySQL

(4) Remove the MySQL Service

Mysqld-NT -- remove

3.2 install MySQL Gui

(1)extract the downloaded mysql-gui-tools-noinstall-5.0-r12-win32.zip to the d:/MySQL-Gui/MySQL GUI tools 5.0 directory.

(2)double-click mysqlsystemtraymonitor.exe under this directory

(3) Use the root user to log on to the page. The password is blank.

(4) After logging in, you can add new users, change passwords, and assign new users permissions to the database in user administration. You can create a schema in catalogs.

(5) You can use this GUI to create stored procedures, tables, and so on.

3.3 install the MySQL ODBC driver

(1) unzip the mysql-connector-odbc-noinstall-3.51.21-win32 to D:/MySQL-ODBC/mysql-connector-odbc-noinstall-3.51.21-win32, you can modify the path.

(2) enter the directory in cmd and run the command

Install 0

After the installation is successful, the MySQL driver is displayed in the data source.

2. VC connects to MySQL through ODBC

1. The code in VC is as follows:

# Define connect_command _ T ("DSN = specialintroduce; driver = {MySQL ODBC 3.51 driver}; uid = cmsuser; Pwd = cmspassword ")

(1) Determine whether the database is connected

Cdatabase m_dbbase;

M_dbbase.setlogintimeout (15 );
Bconnect = m_dbbase.openex (connect_command, cdatabase: openreadonly | cdatabase: noodbcdialog );

(2) Call the Stored Procedure example

Cstring strsql;
Strsql. Format (L "{call procgetspecialmenuinfobysmname ('% s')}", strmname );
Try
{
Recordset. Open (crecordset: forwardonly, strsql, crecordset: readonly );
}
Catch (cexception * E)
{
E-> reporterror ();
}
While (! Recordset. iseof ())
{
Recordset. getfieldvalue (_ T ("SMID"), VAR );
Menuinfos. Mid = (INT) var. m_ival;
Recordset. getfieldvalue (_ T ("smname"), menuinfos. mname );
Recordset. getfieldvalue (_ T ("smprice"), menuinfos. mprice );
Recordset. getfieldvalue (_ T ("smmeasure"), menuinfos. mmeasure );
Recordset. movenext ();
}
Recordset. Close ();

Finally, if the VC interface displays Chinese characters, you can select gb2312 from the character set option on the connection options interface When configuring the data source.

Iii. MySQL table creation and stored procedure examples

Drop table if exists 'tablename ';
Create Table if not exists 'tablename'
(
'Smid' int unsigned not null auto_increment,
'Smname' varchar (20) not null,
'Smname1' varchar (20) not null,
'Smmeasure 'varchar (6) Not null,
'Smprice 'decimal () not null,
'Smstatus' bit not null default 1,
'Smremark' varchar (200 ),
Constraint fk_tablename_smid primary key ('smid '),
Constraint uq_tablename_smname unique ('smname ')
Engine = InnoDB auto_increment = 1000 default charset = utf8;

 

Delimiter $

Drop procedure if exists 'schemaname'. 'procgetxx' $
Create procedure 'schemaname'. 'procgetxx' (smnames varchar (20 ))
Begin
Select
'Smid ',
'Smname ',
'Smprice ',
'Smmeasure'
From
'Tablename'
Where
'Smname' = smnames;
End $

Delimiter;

Delimiter $

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.