---
# System prepended metadata

title: Mysql

---

# Mysql 
匯入 sql 的指令：

    mysql -u {DB帳號} -p {databaseName} < {sql file name }
    ex: mysql -u admin -p cosc < account.sql

連線DB指令

    mysql -u {DB帳號}
    ex: mysql -u admin

###     進入DB後的操作

選擇連線的 Database

    use {DatabaseName}
    ex: use cosc
    
![](https://i.imgur.com/q7lMiv7.png)

下SQL指令，如果有資料就會顯示圖1，沒有資料就會顯示圖2
    
    select {FieldName} from {TableName} where {FieldName} = '{Value}';
    
    ex:select Account from Employee where Account = 'COSC-TM36';
    
圖1
![](https://i.imgur.com/0lgr2MQ.png)
圖2
![](https://i.imgur.com/6Ki8GfC.png)

# 匯入匯出

匯出 -

    mysqldump -u {account} -p {databasename} > ./sqlname.sql
    
    ex: mysqldump -uroot -p test1 > ./sqlname.sql
匯入 -

    mysql  -u {account} -p {databasename} < ./sqlname.sql
    
    ex: mysql -uroot -p test1 < ./sqlname.sql
    
建立DB -

    Create database {databaseName};
    
    ex: create database test1;