MySql binary connection mode and mysql binary connection

Source: Internet
Author: User

MySql binary connection mode and mysql binary connection

Connect using mysql binary

You can use the MySQL binary method to enter the mysql Command Prompt and connect to the MySQL database.

Instance

The following is a simple example of connecting to the mysql server from the command line:

Copy codeThe Code is as follows:
[Root @ host] # mysql-u root-p
Enter password :******

After successful logon, the mysql> Command Prompt window appears. You can execute any SQL statements on it.

After the preceding command is executed, the result of successful logon is as follows:

Welcome to the MySQL monitor. Commands end with; or \ g.
Your MySQL connection id is 2854760 to server version: 5.0.9
Type 'help; 'or' \ H' for help. Type '\ C' to clear the buffer.

In the above example, we use the root user to log on to the mysql server. Of course, you can also use other mysql users to log on.

If you have sufficient permissions, any user can perform SQL operations in the mysql Command Prompt window.

Exit mysql> the Command Prompt window can use the exit command, as shown below:

Copy codeThe Code is as follows:
Mysql> exit
Bye

Use a PHP script to connect to MySQL

PHP provides the mysql_connect () function to connect to the database.

The function has five parameters. After successfully linking to MySQL, the connection ID is returned. If the function fails, FALSE is returned.

Syntax

Copy codeThe Code is as follows:
Connection mysql_connect (server, user, passwd, new_link, client_flag );

Parameter description:

Parameters Description
Server

Optional. Specifies the server to be connected.

It can include the port number, for example, "hostname: port", or the path to the local socket, for example, ":/path/to/socket" for localhost ".

If the PHP Command mysql. default_host is not defined (the default value is true), the default value is 'localhost: 3306 '.

User Optional. User name. The default value is the user name of the server process owner.
Passwd Optional. Password. The default value is null.
New_link Optional. If the same parameter is used to call mysql_connect () for the second time, a new connection is not established, but an opened connection ID is returned. The new_link parameter changes this behavior and makes mysql_connect () always open a new connection, even when mysql_connect () was previously called with the same parameter.
Client_flag

Optional. The client_flags parameter can be a combination of the following constants:

  • MYSQL_CLIENT_SSL-SSL encryption
  • MYSQL_CLIENT_COMPRESS-use the compression Protocol
  • MYSQL_CLIENT_IGNORE_SPACE-interval after the function name is allowed
  • MYSQL_CLIENT_INTERACTIVE-allow interaction timeout and inactivity before closing the connection

You can use the mysql_close () function of PHP to disconnect from the MySQL database.

This function only has one parameter that is the MySQL connection identifier returned after the mysql_connect () function is successfully created.

Syntax

bool mysql_close ( resource $link_identifier );

This function disables the non-persistent connection associated with the specified connection ID to the MySQL server. If link_identifier is not specified, the last opened connection is closed.

Note: you do not need to use mysql_close () because a non-persistent connection is automatically closed after the script is executed.

Note: mysql_close () does not close persistent connections established by mysql_pconnect.

Instance

You can try the following instances to connect to your MySQL Server:

<Html> 

The above is a detailed description of the MySql binary connection method introduced by the small Editor, hoping to help you!

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.