Code:
<?php
$host = 'localhost'; // MySQL host name
$user = 'root'; // MySQL database user name
$pass = 'root'; // MySQL database user password
$db = 'dbname'; // MySQL database name
$connect = @mysql_connect ($host,$user,$pass) or die ('Error connecting to database!');
$select = @mysql_select_db ($db) or die ('Error selecting database!');
?>
Now you are connected to MySQL. Save this file as mysql.php or something and include it on every page that needs a MySQL connection.
As for Javascript accessing MySQL, that is called AJAX and you need a pretty good knowledge of Javascript and XML before you get into that.