Linux 安装Xampp以后,Apache服务器无法启动,以及启动后,连接sql数据库遇到的问题的解决方法

xampp安装以后,搭建服务器的时候,我们会遇到哪些问题呢?
1、MySQL Database 可以启动,而Apache Web Server无法启动?
应该是80端口被占用,那么如何解决呢?我们可以通过查找80被哪个占用,并关闭这个进程,方法如下:

 root@bt:/# netstat -lntp | grep :
tcp 0.0.0.0: 0.0.0.0:* LISTEN /apache2

关闭该服务,

 root@bt:/# sudo service apache2 stop
* Stopping web server apache2 .. waiting .. [ OK ]

成功关闭。接下来,就可以启动Apache Web Server ,端口为 80.

2、在成功开启Apache Web Server 服务以后,就想调试 mysql ,发现 MySQL Database 虽然启动,但是无法打开连接sql,并出现以下错误

 root@bt:/opt/lampp/var/mysql# mysql -u root -p
Enter password:
ERROR (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

这时候,我就在想如何找到 mysqld.sock 到底在什么位置? 最终没能找到,只能找到 mysql.sock 位于

 root@bt:/opt/lampp/var/mysql# ls
aria_log. bt.pid ibdata1 multi-master.info performance_schema tc.log
aria_log_control challenges ib_logfile0 mysql phpmyadmin test
bt.err dvwa ib_logfile1 mysql.sock security

好的,当我们找到 mysql.sock以后,我们右键点击创建链接,并且重命名为 mysqld.sock 然后右键剪切该文件,

并把它放到显示错误提示的路径中 ,即到/var/run/下,如果没有mysqld文件夹,就得新建一个,并把mysqld.sock放进去。
那么现在就有了mysqld.sock文件,并且在/var/run/mysqld/mysqld.sock 这里。
现在,我们就可以运行

 root@bt:/# mysql -u root -p
Enter password:
ERROR (): Access denied for user 'root'@'localhost' (using password: YES)

发现还是出错,这是因为之前,找不到mysqld.sock,以为是密码不对,就修改了 /opt/lampp/etc/下的my.cnf,把password改回

为默认的your_name,实际上,就是空密码。内容如下

 # The following options will be passed to all MySQL clients [client]
#password =your_name
port = 3306
socket = /opt/lampp/var/mysql/mysql.sock

好的,再次运行

 root@bt:/# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is
Server version: 5.5.-10.1.-MariaDB Source distribution
...
mysql>

成功完成,mysql的连接。

Reference::
1.http://*.com/questions/11990708/error-cant-connect-to-local-mysql-server-through-socket-var-run-mysqld-mysq

上一篇:12C数据库ORA-40365: The SYS user cannot be locked while the password file is in its current format


下一篇:perl 分析mysql binlog