Setting up Arduino with mysql database

Hey guy I am new to the forum so go easy on me, and a newbie to Arduino yun. Okay here is my problem… I am having trouble setting up the connect between php and mysql connection. First, Install this package

opkg update
opkg install libpthread libncurses libreadline mysql-server

sed -i 's,^datadir.*,datadir         = "/srv/mysql",g' /etc/my.cnf
sed -i 's,^tmpdir.*,tmpdir          = "/tmp",g' /etc/my.cnf

mkdir -p /srv/mysql
mysql_install_db --force

/etc/init.d/mysqld start
/etc/init.d/mysqld enable

mysqladmin -u root password 'new-password'

opkg update
opkg install php5-mod-mysql

sed -i 's,;extension=mysql.so,extension=mysql.so,g' /etc/php.ini

I followed these instructions from

http://wiki.openwrt.org/doc/howto/lamp

Then I edited my php.ini file to run mysql in php

nano /etc/php.ini

here are the change I made to php.ini

[MySQL]
mysql.allow_local_infile = On
mysql.allow_persistent = On
mysql.cache_size = 2000
mysql.max_persistent = -1
mysql.max_links = -1
mysql.default_port = 3306
mysql.default_socket = /tmp/run/mysqld.sock
mysql.default_host = 192.168.x.x
mysql.default_user = root
mysql.default_password = new-password
mysql.connect_timeout = 60
mysql.trace_mode = Off

After that I use mysqladmin -u root -p create arduino to create a database

Finally I use mysql -u root -p to create a table and populate the table using mysql commands

here is my php code

<?php  
	
 // sql command is mysql -u root -p

$DBServer = '192.168.x.x'; 
$DBUser   = 'root';
$DBPass   = 'new-password';
$DBName   = 'arduino';  
$conn = mysql_connect($DBServer, $DBUser, $DBPass); not connecting 

  if (isset($_GET)){ 
	
	  $DoorBell_State  =$_GET["value"]; 
	 
	  
	  echo $DoorBell_State;
	  
	  }
	  
	  "
"; 
	  
	  "
"; 
	  
	//  echo "Date and Time"; 
	  
	  
	  
	  
	  
	
?>

In the end when I try to connect to the database I get

Warning: mysql_connect(): Lost connection to MySQL server at 'reading initial communication packet', system error: 146 in /mnt/sda1/Front/index.php on line 15

Can SomeOne please help me connect to my … mysql database on my board. I want to Insert a GET evens into my sql database on the board…

any help would be deeply appreciated

Thanks

Sean

P.S a pointer to a good and clear tutorial would be helpful

:slight_smile:

Install Mysql server

Php and Mysql

You still use MySQL shared module extension:

MySQL shared module extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi (MySQL Improved Extension) or PDO_MySQL extension should be used.

Thanks bro your tutorial work! I have mysql running how I want it .. it turn out i didn't have to edit php.ini to get mysql to work. Your a live saver ..

bro, mark subject as "[SOLVED]" please.