php mysql连接不上的解决办法:1、建立一个PHP文件显示“phpinfo()”;2、获取MySQL socket路径;3、重新配置PHP;4、重启nginx或者apache即可。
千万级数据并发如何处理?进入学习
本文操作环境:Windows7系统、PHP5.5.34版、DELL G3电脑
php mysql上不去怎么办?
PHP连接不上MySQL解决方案总结
1. 获取当前 mysql.default_socket、mysqli.default_socket、pdo_mysql.default_socket 配置信息
建立一个 PHP 文件, 显示 phpinfo():
用浏览器打开:
在此页面,找到mysql.default_socket、mysqli.default_socket、pdo_mysql.default_socket信息:
2. 获取 MySQL socket 路径
通过控制台进入 MySQL, 输入命令: STATUS, 查找 UNIX socket 值
#mysql -u root -pEnter password: Welcome to the MySQL monitor.Commands end with ; or \g.Your MySQL connection id is 8Server version: 5.7.11 MySQL Community Server (GPL)Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.mysql> STATUS--------------mysqlVer 14.14 Distrib 5.7.11, for osx10.9 (x86_64) usingEditLine wrapperConnection id:8Current database:Current user:root@localhostSSL:Not in useCurrent pager:lessUsing outfile:‘‘Using delimiter:;Server version:5.7.11 MySQL Community Server (GPL)Protocol version:10Connection:Localhost via UNIX socketServer characterset:utf8Db characterset:utf8Client characterset:utf8Conn.characterset:utf8UNIX socket:/tmp/mysql.sockUptime:8 days 15 hours 1 min 17 secThreads: 2Questions: 21Slow queries: 0Opens: 114Flush tables: 1Open tables: 0Queries per second avg: 0.000--------------
登录后复制
3. 这时候, 你对比 mysql.default_socket、mysqli.default_socket、pdo_mysql.default_socket 和 通过 MySQL UNIX socket 发现不一样, 这就是 mysql_connect(); 警告的原因: PHP 配置 mysql 有问题.
4. 重新配置 PHP, 打开php.ini修改mysql.default_socket、mysqli.default_socket、pdo_mysql.default_socket 的值为: /tmp/mysql.sock
pdo_mysql.default_socket=/tmp/mysql.sockmysql.default_socket=/tmp/mysql.sockmysqli.default_socket=/tmp/mysql.sock
登录后复制
或者修改my.cnf的socket:
[client]socket=/tmp/mysql.sock[mysqld]socket=/tmp/mysql.sock
登录后复制
5.重启nginx或者apache
推荐学习:《PHP视频教程》
以上就是php mysql上不去怎么办的详细内容,更多请关注php中文网其它相关文章!