To connect to database on the same server as the PHP program using the database: @$d = mysql_connect('localhost','database_username','database_password') or die("Can't connect"); ============================================ To connect to database on a server different than that of the PHP program using the database, you put the full name of the server or its IP address: @$d = mysql_connect('pizza.cs.fredonia.edu','database_username','database_password') or die("Can't connect"); or @$d = mysql_connect('127.0.0.1','database_username','database_password') or die("Can't connect"); ============================================ To create a table called dt (you can call it something else) in the current database as (description and records) the table dt in database sp07, you do this: mysql> create table dt select * from sp07.dt; ============================================= To select the first two records from table news: SELECT * from news limit 0,2 ============================================== To select the first two records from table news and order them in ascending order with respect to the name (note that the default is ascending so no need for asc below): SELECT * from news limit 0,2 order by name asc =============================================== To select the first two records from table news and order them in descending order with respect to the name SELECT * from news limit 0,2 order by name desc ============================================== To change your database password: set password = password("new_password"); ============================================== To change your database password and make it possible to recover the old password: SET PASSWORD = OLD_PASSWORD('newpassword'); =============================================== To create a database called iyad for user called abu-jeib with password pass: GRANT ALL PRIVILEGES ON iyad.* TO 'abu-jeib@localhost' IDENTIFIED BY 'pass' WITH GRANT OPTION; =============================================== To list files with respect to the modification date and output the result to a file called t.txt (you can add a path and put the file in a different directory): ls -lt * >> t.txt =================================================== To copy a database to file table.sql (you can add a path and put the file in a different directory) from database old_db_name: mysqldump -u USERNAME -p old_db_name > table.sql =================================================== To copy table.sql file to a database called new_db_name: mysql -u USERNAME -p new_db_name < /path/table.sql ================================================== To create table t2 in database db2 like (i.e. with same description) table t1 in database db1: use db2; create table t2 like db1.t1; To insert the records of table t1 into table t2: insert into t2 select * from db1.t1; ================================================== To output the mysql query to a file (the directory containing the file must have writing permissions): SELECT name, grade FROM students INTO OUTFILE '/home/abu-jeib/Temp/info.txt'; ====================================================== To output the mysql query to a file (the directory containing the file must have writing permissions), separate the fields/columns by commas and enclose them in double quotes, and to put each record on a different line: SELECT name, grade FROM students INTO OUTFILE '/home/abu-jeib/Temp/info.txt' FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\n';