在redhat下安装了mysql,在mysql控制台下,可以使用localhost连接,但是在php中连接时,却不行,而使用127.0.0.1能连上,查看了hosts文件,发现有127.0.0.1和localhost的对应
哪位大侠知道是怎么回事
------解决方案--------------------
是不是你在建站点的时候设置了站点为http://127.0.0.1了呢?
------解决方案--------------------
看一看你的mysql是怎么配置的,
检查mysql启动后/usr/local/mysql/var/mysql.sock是否存在。
------解决方案--------------------
Description
A frequent error message received when using the mysql command line utility is: Can 't connect to local MySQL server through socket '/tmp/mysql.sock ' While this error message can be frustrating, the solution is simple.
Directions
When connecting to a MySQL server located on the local system, the mysql client connects thorugh a local file called a socket instead of connecting to the localhost loopback address 127.0.0.1. For the mysql client, the default location of this socket file is /tmp/mysql.sock. However, for a variety of reasons, many MySQL installations place this socket file somewhere else like /var/lib/mysql/mysql.sock.
While it is possible to make this work by specifying the socket file directly in the mysql client command
mysql --socket=/var/lib/mysql/mysql.sock ...
it is painful to type this in every time. If you must do so this way (because you don 't have permissions to the file in the solution below), you could create an alias in your shell to make this work
(like alias mysql= "mysql --socket=/var/lib/mysql/mysql.sock " depending on your shell).
To make your life easier, you can make a simple change to the MySQL configuration file /etc/my.cnf that will permanently set the socket file used by the mysql client. After making a backup copy of /etc/my.cnf, open it in your favorite editor. The file is divided into sections such as
[mysqld]
datadir=/usr/local/mysql/data
socket=/var/lib/mysql/mysql.sock
[mysql.server]
user=mysql
basedir=/usr/local/mysql
If there is not currently a section called [client], add one at the bottom of the file and copy the socket= line under the [mysqld] section such as:
[client]
socket=/var/lib/mysql/mysql.sock
If there is already a [client] section in the my.cnf file, add or edit the socket line as appropriate. You won 't need to restart your server or any other processes. Subsequent uses of the mysql client will use the proper socket file.
相关文章推荐
• PHP集成环境推荐解决思路 • 各位大大一起来帮忙看一下!解决办法 • PHP:路在何方?• 【PHP开发】国外程序员收集整理的 PHP 资源大全,国外收集整理_PHP教程• 解密ThinkPHP3.1.2版本之模板继承_PHP教程jquery 基础视频教程
jQuery 很容易学习,希望通过我们的《jquery 基础视频教程》可以帮助大家来更好的学习jQuery。 jQuery 是一个 JavaScript 库,简化了 JavaScript 编程。
jQuery教程50358次播放
javascript三级联动视频教程
《javascript三级联动视频教程》介绍了javascript开发的三级联动功能,该功能在日常使用中还是经常能用的到的一个。
JavaScript教程29730次播放
独孤九贱(3)_JavaScript视频教程
javascript是运行在浏览器上的脚本语言,连续多年,被评为全球最受欢迎的编程语言。是前端开发必备三大法器中,最具杀伤力。如果前端开发是降龙十八掌,好么javascript就是第18掌:亢龙有悔。没有它,你的前端生涯是不完整的。《php.cn独孤九贱(3)-JavaScript视频教程》课程特色:php中文网原创幽默段子系列课程,以恶搞,段子为主题风格的php视频教程!轻松的教学风格,简短的教学模式,让同学们在不知不觉中,学会了javascript知识。
JavaScript教程118815次播放
独孤九贱(6)_jQuery视频教程
jQuery是一个快速、简洁的JavaScript框架。设计的宗旨是“write Less,Do More”,即倡导写更少的代码,做更多的事情。它封装JavaScript常用的功能代码,提供一种简便的JavaScript设计模式,优化HTML文档操作、事件处理、动画设计和Ajax交互。 核心特性可以总结为:具有独特的链式语法和短小清晰的多功能接口;具有高效灵活的css选择器,并且可对CSS选择器进行扩展;拥有便捷的插件扩展机制和丰富的插件。兼容各种主流浏览器,如IE 6.0+、FF 1.5+、Safari 2.0+、Opera 9.0+等,是全球最流行的前端开发框架之一。PHP中文网根据最新版本,独家录制jQuery最新视频教程,回馈PHP中文网的新老用户。
jQuery教程98148次播放