MySQL
To login (from unix shell) use -h only if needed.
[mysql dir]/bin/mysql -h hostname -u root -p
Create a database on the sql server.
create database [databasename];
List all databases on the sql server.
show databases;
Switch to a database.
use [db name];
To see all the tables in the db.
show tables;
To see database's field formats.
describe [table name];
To delete a db.
drop database [database name];
To delete a table.
drop table [table name];
Show all data in a table.
SELECT * FROM [table name];
Returns the columns and column information pertaining to the designated table.
show columns from [table name];
Show certain selected rows with the value "whatever".
SELECT * FROM [table name] WHERE [field name] = "whatever";
Show all records containing the name "Bob" AND the phone number '3444444'.
SELECT * FROM [table name] WHERE name = "Bob" AND phone_number = '3444444';
Show all records not containing the name "Bob" AND the phone number '3444444' order by the phone_number field.
SELECT * FROM [table name] WHERE name != "Bob" AND phone_number = '3444444' order by phone_number;
Show all records starting with the letters 'bob' AND the phone number '3444444'.
SELECT * FROM [table name] WHERE name like "Bob%" AND phone_number = '3444444';
สำหรับ database เล็กๆ ใช้ phpmyadmin ก็สะดวกดี แต่ถ้า database ขนาดใหญ่ หลายล้าน records ล่ะ ก็คงไม่สะดวก ยิ่ง Server config ให้ PHP เป็น safe mode ก็จะมีปัญหากับ time-out ซึ่งทำให้ใช้ phpMyAdmin ไม่ได้
เขียน PHP scripts ให้ backup database โดยการ generate เป็น ไฟล์ SQL เก็บเอาไว้
มันก็ใช้งานได้ดีอยู่.. แต่มันทำงานได้ช้ามาก (เกือบ 1 ชั่วโมง สำหรับ database ขนาด 300 MB)
สำหรับการ backup database ขนาดใหญ่แล้ว ผมคิดว่า mysqldump นั้นมีประสิทธิภาพมากที่สุดแล้ว
ทั้งๆที่มากับ mysql อยู่แล้ว :) เลยมาลองใช้สิ่งที่ MySQL จัดเตรียมมาให้แล้ว
การ backup
คำสั่งสำหรับ backup ฐานข้อมูล ของ mysql คือ mysqldump รูปแบบการใช้งานมีดังต่อไปนี้
shell> mysqldump [options] db_name [tables]
shell> mysqldump [options] --databases db_name1 [db_name2 db_name3...]
shell> mysqldump [options] --all-databases
สำหรับรายละเอียดของ options ต่างๆ ดูที่ http://dev.mysql.com/doc/refman/5.0/en/mysqldump.html
ตัวอย่างการใช้งาน
1.ติดตั้ง cvsup กันก่อนครับ
# cd /usr/ports/net/cvsup-without-gui
# make install clean
# /usr/local/bin/cvsup -g -L 2 -h cvsup.sg.freebsd.org /usr/share/examples/cvsup/ports-supfile
2.Compile Kernel ให้ support smp
ตรงนี้จะสร้าง rule ของ ipfw ไว้ก่อน ตอน reboot ใหม่จะได้ไม่ deny all
# vi /etc/rc.local
ใส่ค่าไปใน /etc/rc.local
ipfw add 100 allow ip from any to any
# chmod 755 /etc/rc.local
# cd /usr/src/sys/i386/conf/
ทำการสร้าง config ของ kernel ใหม่ที่ต้องการ
load ได้ที่ http://ton.212cafe.com/download/LAO.txt
# fetch http://ton.212cafe.com/download/LAO.txt
# cp -Rp /boot/kernel /boot/kernel.ok
# cd /usr/src
# make -j4 kernel KERNCONF=LAO
# shutdown -r now
พอเครื่องขึ้นมาอีกครั้งนึง ดู kernel ใหม่
# uname -a
FreeBSD freebsd04.gmember.com 5.5-STABLE FreeBSD 5.5-STABLE #0: Thu Jan 25 17:12:29 ICT 2007
root@freebsd04.gmember.com:/usr/obj/usr/src/sys/LAO i386
3.MySQL
# cd /usr/ports/databases/mysql41-server
# make install WITH_CHARSET=tis620
# rehash
# vi /etc/rc.conf
ให้ MySQL ทำงานทุกครั้งเมื่อเปิดเครื่อง
mysql_enable="YES"
# /usr/local/etc/rc.d/mysql-server.sh start
Step 1 installation of PureFTPd & MySQL.
Installation of the MySQL server:
ในขั้นตอนแรกนี้ หาก ยังไม่ได้ติดตั้ง Mysql Server ให้ทำการติดตั้งก่อนครับ ในที่นี้ จะติดตั้ง Mysql 4.0 น่ะครับความชอบส่วนตัว
Shell:
cd /usr/ports/databases/mysql40-server |
หลังจากติดตั้งเสร็จแล้วน่ะครับ ให้ไปเพิ่มบรรทัด ใน /etc/rc.conf เพื่อให้ msql รันทุกครั้งท่เปิดเครื่องครับ
Editor:

: Support :