MySQL Command เบื้องต้นที่ใช้งานบ่อย

NottDev
1 min readFeb 22, 2021

--

สำหรับคนที่ใช้ฐานข้อมูล MySQL จะต้องเจอกับสถานการณ์การ Backup ข้อมูล การ Restore ข้อมูล หรือการย้ายข้อมูลจาก Server หนึ่งไปอีก Server หนึ่ง บทความนี้จะมาแนะนำคำสั่งเบื้องต้นที่ใช้งานบ่อย มีอะไรบ้างไปดูกันเลย >.<

เนื้อหาประกอบด้วย

  1. การ export ทั้งโครงสร้างและข้อมูล
  2. การ export เฉพาะโครงสร้าง
  3. การ export เฉพาะข้อมูล
  4. การ export แค่ 1 ตาราง
  5. การ export แบบยกเว้นตาราง
  6. การ import ข้อมูล

Dumping structures and data

To export structure and data run the following command

$  mysqldump -p -u [username] [dbname] > [dbname].sql

Dumping structures only

To export structures only run the following command

$  mysqldump -u [username] -p --no-data [dbname] > [dbname].sql

Dumping data only

To export data only run the following command

$  mysqldump -u -p [username] --no-create-info [dbname] > [dbname].sql

Dumping one table

To export one table run the following command

$ mysqldump -u [username] -p [dbname] [tablename] > [tableName].sql

Dumping ignore table

To export exclude tables run the following command

$ mysqldump -u [username] -p [dbname] --ignore-table=DB_NAME.table > [tableName].sql

Import data

To import the data run the following command

$ mysql -u [username] -p -D [dbname] < [tableName].sql

Reference:

--

--

NottDev
NottDev

Written by NottDev

Your only limit is your mind.

No responses yet