PHP uses mysqli function to connect MySQL appears Warning:mysqli::real_connect (): (hy000/1040): ... _php instance

Source: Internet
Author: User
Tags fpm

Background: The MySQL into mysqli, the number of connections, it is not in fact, because I moved a bit of PHP sock file location caused by these several socket modifications have not been modified completely, so there have been too many connections, From the MySQL show Processlist did not find that there is really a connection, in fact, with Tshark grasp the package can be seen (http://justwinit.cn/post/7458/), and did not issue a request, And it is estimated that the client of mysqli, although the problem is small, engaged in a long time, all want to reinstall PHP, found that the path is wrong to write the same time mysqli the client prompts the number of connections too many false hints led to the wrong direction. As follows:

[Root@iz25z0ugwgtz etc]# grep-r "Mysql.sock"./
./php.ini:pdo_mysql.default_socket=/data/runsock/mysqlsock/ Mysql.sock
./php.ini:;mysql.default_socket =/tmp/mysql.sock
./php.ini:mysql.default_socket =/data/ Runsock/mysqlsock/mysql.sock
/php.ini:mysqli.default_socket =/data/runsock/mysql.sock//This position is moved to,/data/ Runsock/mysqlsock/mysql.sock caused.

Remember to restart PHP-FPM after modification:

[ROOT@IZ25Z0UGWGTZ etc]# service php-fpm restart gracefully shutting down php-fpm
. Do
starting php-fpm done

______________________ troubleshooting points are as follows _______________________________

Warning:mysqli::real_connect (): (hy000/1040): Too many connections in:

scene: manually compile and install MySQL, and set the installation location, PHP to connect MySQL localhost way

cause Analysis: Manually compile installation location after all the MySQL files are in the development of the directory or the data directory, PHP default will only look for/temp/mysql.sock find this sock file, so will cause sock file can not find.

Workaround:

1. Make a soft chain for sock files

Ln-s/data/mysqldb/mysql.sock/tmp/mysql.sock;

Or

2. Modify PHP default Mysql.sock connection address

Mysql.default_socket=/data/mysqldb/mysql.sock

3. Connect using a TCP socket

MySQL (' 127.0.0.1 ', ' username ', ' passwod ');

Here to introduce PHP mysql_connect () function

Definitions and usage

The mysql_connect () function opens a non-persistent MySQL connection.

Grammar

Mysql_connect (Server,user,pwd,newlink,clientflag)

parameters Description
server

Optional. Specify the server to connect to.

Can include a port number, such as "Hostname:port", or a path to a local socket, such as ":/path/to/socket" for localhost.

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

user is optional. User name. The default value is the user name of the server process owner.
pwd is optional. Password. The default value is a blank password.
newlink is optional. If mysql_connect () is invoked the second time with the same argument, no new connection will be established, and the connection ID that is already open will be returned. The parameter New_link changes this behavior and causes mysql_connect () to always open a new connection, even when mysql_connect () was previously invoked with the same parameters.
clientflag

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

    Mysql_client_ssl-using SSL encryption
  • Mysql_c Lient_compress-Use the compression protocol
  • Mysql_client_ignore_space-Allow the interval after the function name
  • mysql_client_interactive-Allow off Interaction timeout before a closed connection time inactive

return value

If successful, returns a MySQL connection identity and returns FALSE if it fails.

Tips and comments

Note: As soon as the script is finished, the connection to the server is closed unless the mysql_close () has been explicitly invoked before.
Tip: To create a persistent connection, use the Mysql_pconnect () function.

Example

<?php
$con = mysql_connect ("localhost", "Mysql_user", "mysql_pwd");
if (! $con)
{
die (' Could not connect: '. Mysql_error ());
}
Some code ...
Mysql_close ($con);
? >
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.