How to connect at MySQL database

Do not forget create a new database and database’s user via Cpanel>>Mysql

Check connection here via command line

mysql -udatabaseuser -hdatabaseserver -ppassword  databasename

Where you need to:

~ replace databaseserver with the correct database servername for your site.

~ replace databaseuser with your own mysql username.

~ replace databasename with your own mysql databasename.


mysql -uvasya_hut -hlocalhost -pdfs435ksja vasya_hut

mysql -uvasya_hut -pdfs435ksja vasya_hut

If you use preferences set in a .my.cnf file, the connection command would be much shorter, just:


– To connect from a PHP script, just put this in your file:

using the same substitutions for the bold terms as above, plus substituting databasepassword with your own mysql password.


mysql_connect(“”, “vasya”, “password”);

– To connect from a perl script, put this in your file:

use DBI;

$database = “databasename”;
$hostname = “”;
$port = “3306″;
$username = “databaseuser”;
$password = ‘databasepassword’;

$dsn = “DBI:mysql:database=$database;host=$hostname;port=$port”;

$dbh = DBI->connect($dsn, $username, $password) or die(“Could not connect!”);

$sql = “SELECT * FROM mytable”;

$sth = $dbh->prepare($sql);

while(($column1, $column2) = $sth->fetchrow_array)
print “C1 = $column1, C2 = $column2n”;


where databasename, databaseuser, and databasepassword are your database name, database username and database password, and where is your website’s domain name with no “www.” in front, for example, “”, or if you are not hosting your own domain name with us, then “”.

Similar Posts:

Leave a Reply

Your email address will not be published. Required fields are marked *