Download presentation
Presentation is loading. Please wait.
Published byAlexina Thompson Modified over 9 years ago
1
1 How to use MySQL? Speaker: Ching-Chen Chang
2
2 Outline Command Line Interface (CLI) Web-based Interface
3
3 Using MySQL CLI $ mysql –u username –p use databasename;
4
4 Information show databases; show tables; describe tablename; select * from tablename; select col1, col2.. from tablename;
5
5 Create Table Create table tablename(….); create table phonebook ( id int, username char(50), phone varchar(50) ); )
6
6 Insert Values to a Table INSERT INTO phonebook VALUES(1, ’Jane’, ‘0911111111’); INSERT INTO phonebook (id, username, phone) VALUES(2, ‘Bob’, ’0912222222’); INSERT INTO phonebook VALUES(1, ’Jane’, ‘0911111111’), (2, ‘Bob’, ’0912222222’); INSERT INTO phonebook (id, username) VALUES(3, ‘Peter’); +------------+--------------+------------------------+ | id | username | phone | +------------+--------------+------------------------+ | 1 | Jane | 0911111111 | | 2 | Bob | 0912222222 | | 3 | Peter | | +------------+--------------+------------------------+
7
7 Update tables UPDATE phonebook SET phone=‘0911333333’ WHERE id=3; UPDATE phonebook SET phone=‘0912444444’ WHERE username=‘Bob’; +------------+--------------+------------------------+ | id | username | phone | +------------+--------------+------------------------+ | 1 | Jane | 0911111111 | | 2 | Bob | 0912444444 | | 3 | Peter | 0911333333 | +------------+--------------+------------------------+
8
8 Delete DELETE FROM phonebook WHERE id=3; drop table tablename; +------------+--------------+------------------------+ | id | username | phone | +------------+--------------+------------------------+ | 1 | Jane | 0911111111 | | 2 | Bob | 0914444444 | +------------+--------------+------------------------+
9
9 JOIN (1/2) select * from phonebook; select * from student; +---------------+--------------+ | studentid | name | +---------------+--------------+ | 91321021 | Jane | | 91321033 | Bob | | 91321040 | Peter | +---------------+--------------+ +------------+--------------+------------------------+ | id | username | phone | +------------+--------------+------------------------+ | 1 | Jane | 0911111111 | | 2 | Bob | 0912444444 | +------------+--------------+------------------------+
10
10 JOIN (2/2) SELECT phonebook.id, student.name, student.studentid, phonebook.phone AS phonenumber FROM phonebook, student WHERE phonebook.username = student.name; +--------------+---------------+---------------+-------------------+ | id | name | studentid | phonenumber | +--------------+---------------+---------------+-------------------+ | 1 | Jane | 91321021 | 0911111111 | | 2 | Bob | 91321033 | 0912444444 | +--------------+---------------+---------------+-------------------+
11
11 Web-base Interface: phpMyAdmin http://stu.csie.ncnu.edu.tw/myadmin/
12
12 connect_db.php <? define('HOST', 'localhost'); define('USER', '91321021'); define('PASS', '262615'); define('DB', '91321021'); mysql_connect(HOST, USER, PASS); mysql_select_db(DB); ?>
13
13 authentication(1/2) - login.php authentication Sign In username: password: http://stu.csie.ncnu.edu.tw/~beautidays.99/db/login2.php
14
14 authentication(2/2) - auth1.php <? include("connect_db.php"); $result = mysql_query(“ SELECT COUNT(*) AS numfound FROM login WHERE id='{$HTTP_POST_VARS['user']}' AND pwd='{$HTTP_POST_VARS['pass']}'"); $result_ar = mysql_fetch_array($result); if ($result_ar['numfound'] < 1) { header('Location: login.php?error=1'); } else{ echo "success!"; } ?>
15
15 Mysql_Query "; $i=1; $num=mysql_num_rows($result); while($i "; $i++; } ?> http://stu.csie.ncnu.edu.tw/~beautidays.99/db/mysql.php
16
16 References MySQL Tutorial – http://dev.mysql.com/doc/refman/4.1/en/tutorial.html
17
17 The end
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.