Archive for April, 2008

Change MySQL Password Through The Command Prompt

At the “mysql>” prompt, type:

set password = password(“yournewpassword”);

Source: Modwest

Leave a Comment

Import SQL File Into MySQL Server Via Command Prompt

This short tutorial will show you how to import a SQL file (dump file) into MySQL server using the command prompt.

First, make sure you already have a database ready to be used. If not, create one in mysql.exe:

CREATE DATABASE database_name;

If you already have the database ready, enter this command in the command prompt:

mysql -u root database_name < file_name.sql;

Source: About.com

Leave a Comment

Connect to MySQL Database

To open a connection to MySQL database using PHP, use the mysql_connect() function.

<?php
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = 'password';

$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');

$dbname = 'petstore';
mysql_select_db($dbname);
?>

It’s a good practice to separate the routine of opening database, closing database, etc and include them later.

index.php

<?php
include 'config.php';
include 'opendb.php';

// ... do something like insert or select, etc

include 'closedb.php';
?>

config.phps

<?php
// This is an example of config.php
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = 'password';
$dbname = 'phpcake';
?>

opendb.phps

<?php
// This is an example opendb.php
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');
mysql_select_db($dbname);
?>

closedb.phps

<?php
// an example of closedb.php
// it does nothing but closing
// a mysql database connection

mysql_close($conn);
?>

Source: php-mysql-tutorial.com

Leave a Comment

Import Database From Local Server to Web Server

This is my attempt to transfer the database from a local server to a web server. I am using the shopping cart engine from Shop-Script.

Backup MySQL Database from the Command Prompt

Make sure the server is up and running. Open the Command Prompt and navigate to the MySQL folder (where the mysql.exe is) and type:

mysqldump -u user_name -p password database_name > File_name.sql

Source: About.com

Create Database Through the CPanel

I would have created the database straight from the phpMyAdmin if I could, but the web host company didn’t allow it . This is because:

You are getting the no privledges line in phpmyadmin because bluehost won’t allow you to make databases through phpmyadmin. This is (AFAIK) because multiple people use the same mysql server and as such they need to prepend your username to the database name to avoid any conflicting database names from different users.

Source: Bluehost Forum

So, I created the database through the CPanel instead:

Read the rest of this entry »

Leave a Comment