How to connect at my MySQL database ?

Before proceeding for this you need to create a database with available Control Panels. Once you have created a database, there are a few ways you can connect to it :

- At a shell prompt you type all one 1 single line:

mysql -u DBUSERNAME -h DBSERVER -p DBNAME175x110 3

with the following replacements of the bolded terms above:

~ Replace DBSERVER with the correct database servername for your site.

~ Replace DBUSERNAME with your own mysql username.

~ Replace DBNAME with your own mysql databasename.

Example:

mysql -u mike -h db.joesmith.com -p mikedb

If you don’t know your MySQL Username or MySQL Databasename, go here.

You will then be prompted for your MySQL password. If you don’t know what that is, go here to set it to something that you will remember.

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

mysql

Once at the MySQL prompt, you can then issue SQL commands directly to the MySQL server. For correct SQL syntax, see the MySQL Manual.

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

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

Example:

mysql_connect(“db.joesmith.com”, “mike”, “secret”);
mysql_select_db(“mikedb”);

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

#!/usr/bin/perl
use DBI;

$database = “DBNAME”;
$hostname = “db.YOURDOMAIN”;
$port = “3306″;
$username = “DBUSERNAME”;
$password = ‘DBPASSWORD’;

$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);
$sth->execute;

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

$dbh->disconnect;

where DBNAME, DBUSERNAME, and DBPASSWORD are your database name, database username and database password, and where YOURDOMAIN is your website’s domain name with no “www.” in front, for example, “mysite.com”, or if you are not hosting your own domain name with us, then “mysite.modwest.com”.

782x50 5

Related Posts:

  • No Related Posts


Online 24X7 Chat Support
 
 
Telephone
Toll Free
Online chat
 
Online 24X7 Email Support
 
Emails
 
 
 
Support
Support email
sales
Sales email
 
Billing
Billing email
 
   
Latest Tutorials & Articles (Updated Daily)
http://blog.eukhost.com
  Forums :
http://www.eukhost.com/forums/