Remotely connect to mysql using an INI File

Source: Internet
Author: User


I used the INI file to remotely connect to mysql. I recently rewritten something and re-wrote the MySql connection. To facilitate flexible application, read mysql connection parameters by reading the INI file. By the way, I learned about the INI file. Www.2cto.com ini format. The INI file consists of multiple sections. [Cpp] [NETWORK] // node host = *. *. *. * // host: Key, IP: Value: user = root pwd = // read without writing: [cpp] GetPrivateProfileString ("NETWORK", "host ","", host. getBuffer (MAX_PATH), MAX_PATH, strFileName); the parameter list of www.2cto.com is sequential: node name, key name, lpdefault, key value, key value length, INI file path lpDefault: if the INI file does not contain the field name or key name specified by the first two parameters, the value is assigned to the variable. return Value: key value. Write: [cpp] WritePrivateProfileString ("NETWORK", "host", "1.2.3.4", strFileName); the parameter list is sequential: node name, key name, key value, and ini file path return value: long, non-zero indicates success, and zero indicates the path of the failed file: 1. the path of the INI file must be complete, and directories at all levels before the file name must exist. Otherwise, the write operation fails and the function returns FALSE. 2. the file name path must be \, because in VC ++, \ represents \. 3. you can also put the INI file in the directory where the program is located. In this case, the lpFileName parameter is :". \ student. ini ". after the configuration file is written, connect: [cpp] mysql_real_connect (& mydata, host, user, pwd, database, port, unix_socket, clientflag ); // The parameters are obtained by reading the file. The data on www.2cto.com is connected to a pile of posts at night and will not be repeated. The mysql connection base class has been written. Upload to the resource later. Another important step is to set the remote connection: 1. Execute mysql-u root-p mysql on the console. The system prompts you to enter the password of the root user of the database, enter the mysql console. The first mysql command is the execution command, and the second mysql command is the system data name, which is different. 2. Run grant all privileges on * ON the mysql console *. * TO 'root' @ '%' identified by 'mypassword' with grant option; 3. mysql> flush privileges; // if the modification takes effect immediately, error 10060 cannot be connected may occur, check whether the firewall has disabled port 3306.

Related Article

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.