source : http://alvinalexander.com/mysql/mysql_connect-cant-connect-local-mysql-server-socket
===========
kondisi awal
===========
<?php
$host="localhost";
$user="root";
$pass="";
$db="ui";
$koneksi=mysql_connect($host,$user,$pass);
mysql_select_db($db);
$tanggal=date("Y-m-d H:i:s");
if ($koneksi)
{
echo "ulangi username dan password";
}else{
?>
<script language="javascript">alert("Gagal Koneksi Database MySql !!")</script>
<?php
}
?>
==================
testing koneksi PHP
==================
root@server:/opt/lampp/htdocs/xampp# php conn.php
PHP Warning: mysql_connect(): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) in /opt/lampp/htdocs/xampp/conn.php on line 6
PHP Warning: mysql_select_db(): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) in /opt/lampp/htdocs/xampp/conn.php on line 7
PHP Warning: mysql_select_db(): A link to the server could not be established in /opt/lampp/htdocs/xampp/conn.php on line 7
<script language="javascript">alert("Gagal Koneksi Database MySql !!")</script>
root@server:/opt/lampp/htdocs/xampp#
=======================
ikuti petunjuk dari source
=======================
root@server:~# mysql -u myusername -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 26
Server version: 5.6.16 Source distribution
Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show variables like '%socket%';
+-----------------------------------------------------------------+--------------------------------------------+
| Variable_name | Value |
+-----------------------------------------------------------------+--------------------------------------------+
| performance_schema_max_socket_classes | 10 |
| performance_schema_max_socket_instances | 231 |
| socket | /opt/lampp/var/mysql/mysql.sock|
+----------------------------------------------------------------+----------------------------------------------+
3 rows in set (0.00 sec)
mysql> ^CCtrl-C -- exit!
Aborted
root@server:~#
========
solution
========
<?php
$host="localhost:/opt/lampp/var/mysql/mysql.sock";
$user="root";
$pass="";
$db="ui";
$koneksi=mysql_connect($host,$user,$pass);
mysql_select_db($db);
$tanggal=date("Y-m-d H:i:s");
if ($koneksi)
{
echo "ulangi username dan password";
}else{
?>
<script language="javascript">alert("Gagal Koneksi Database MySql !!")</script>
<?php
}
?>
=======
output
=======
root@server:~# cd /opt/lampp/htdocs/xampp
root@server:/opt/lampp/htdocs/xampp# php conn.php
ulangi username dan passwordroot@server:/opt/lampp/htdocs/xampp#
0 komentar:
Posting Komentar