By default remote access to MySQL database server is disabled for security reasons. However, some time you need to provide remote access to database server from home or a web server.
Working on fedora 10, php 5.3.2 and mysql Server version: 5.1.47
Edit my.cnf File
Red Hat Linux/Fedora/Centos Linux file is located at /etc/my.cnf location
opne this file and search [mysqld]
and add bellow line
port = 3306
bind-address = your system ip
service mysqld restart
Open port 3306
open TCP port 3306 using iptables.
A sample iptables rule to open Linux iptables firewall
/sbin/iptables -A INPUT -i eth0 -p tcp --destination-port 3306 -j ACCEPT
save all rules
service iptables save
Example
<?php
$link = mysql_connect('host ip', 'username', 'password');
if (!$link) {
die('Could not connect: ' . mysql_error());
exit;
}
$db_selected = mysql_select_db('database',$link);
if (!$db_selected) {
die ('Can\'t use database : ' . mysql_error());
exit;
}
$sql = "SELECT id as col1, col2, col3 FROM sometable";
$result = mysql_query($sql);
if (!$result) {
echo "Could not successfully run query ($sql) from DB: " . mysql_error();
exit;
}
if (mysql_num_rows($result) == 0) {
echo "No rows found, nothing to print so am exiting";
exit;
}
while ($row = mysql_fetch_assoc($result)) {
echo $row["col1"];
echo " ".$row["col2"];
echo " ".$row["col3"];
}
mysql_free_result($result);
mysql_close($link);
?>
Base on : http://www.cyberciti.biz/tips/how-do-i-enable-remote-access-to-mysql-database-server.html
Freelance Web Programmer, Android, Php 5, java, MySql, JQuery, Symfony framework, Smarty template, facebook application, googlemap application
Tuesday, April 19, 2011
Thursday, April 7, 2011
windows desktop corrupted
if windows desktop corrupted
then copy explorer.exe from working windows folder to corrupted deskotp windows folder (same version)
then copy explorer.exe from working windows folder to corrupted deskotp windows folder (same version)
Subscribe to:
Posts (Atom)
how to see xml preview in browser php
xml preview view in browser $xml = new DOMDocument('1.0', 'UTF-8'); $xml->preserveWhiteSpace = false; ...
-
Weather In Summer: 33.8 C (Max) - 23.3 C (Min) In winter: 20.3 C (Max) - 0 C (Min) Rainy Season : from July to Mid Sept, and very humid (Upt...
-
go to In httpd.conf add comment bellow line userdir disabled ----------------------------------------------- chmod 711 for /home/userdir(use...
-
The contents of my /etc/selinux/config # This file controls the state of SELinux on the system. # SELINUX=permissive # enforcing - ...