When mysql is connected using mysqli function in PHP, the following error occurs: warning: mysqli: real_connect (): (hy000/1040):..., mysqlihy000.

Source: Internet
Author: User

When mysql is connected using mysqli function in PHP, the following error occurs: warning: mysqli: real_connect (): (hy000/1040):..., mysqlihy000.

Background: when mysql is changed to mysqli, there are too many connections. Actually, this is not because I moved the sock File Location of php, because these socket modifications were not completely modified, so the emergence of too connector connections, from mysql show processlist and did not find a real connection, in fact, the use of tshark to capture the package is estimated to see (http://justwinit.cn/post/7458/), and did not send a request, I guess it was reported by the mysqli client. Don't look at this problem. After a long time, I wanted to reinstall Php, it turns out that the path is wrong, and the client of mysqli prompts that the number of connections is too large, leading to incorrect 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 location is moved to/data/runsock/mysqlsock/mysql. caused by sock.

After modification, remember to restart php-fpm:

[root@iZ25z0ugwgtZ etc]# service php-fpm restartGracefully shutting down php-fpm . doneStarting php-fpm done

______________________ The troubleshooting points are as follows _______________________________

Warning: mysqli: real_connect (): (hy000/1040): too connector connections in:

Scenario:Manually compile and install mysql, and set the installation location. php connects to mysql in localhost mode.

Cause analysis:All mysql files after manual compilation and installation are under the specified directory or data directory. By default, php only searches for/temp/mysql. the sock file cannot be found.

Solution:

1. Create a soft link for the sock File

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

Or

2. Modify the default mysql. sock connection address of php.

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

3. tcp socket connection

Mysql ('127. 0.0.1 ', 'username', 'passwod ');

The following describes the PHP mysql_connect () function.

Definition and usage

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

Syntax

mysql_connect(server,user,pwd,newlink,clientflag)

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.
Pwd Optional. Password. The default value is null.
Newlink 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.
Clientflag

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

Return Value

If the connection succeeds, a MySQL connection ID is returned. If the connection fails, FALSE is returned.

Tips and comments

Note: When the script ends, the connection to the server is closed, unless mysql_close () has been explicitly called 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);?>
Articles you may be interested in:
  • Mysql error 1130 hy000: Host ''localhost'' Solution
  • Details about remote connection to the Mysql database (ERROR 2003 (HY000 ))
  • Mysql ERROR handling ERROR 1786 (HY000)
  • Mysql ERROR handling ERROR 1665 (HY000)
  • MySQL ERROR 2002 (HY000): Can't connect to local MySQL server through socket
  • MySQL ERROR 2013 (HY000) Solution
  • Mysql is caused by a common ERROR 1135 (HY000) ERROR.

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.