MySQL匯出資料庫、資料庫表結構、預存程序及函數【用】

來源:互聯網
上載者:User

標籤:select   socket   ogr   int   class   tables   comm   mysqldump   .so   

一、匯出資料庫

    

我的mysql安裝目錄是D:\Program Files\MySQL\MySQL Server 5.5\bin\,匯出檔案預計放在D:\sql\

    在mysql的安裝目錄執行命令: mysqldump -hhostname -uusername -ppassword databasename > d:\sql\databasename.sql

 

 

 在mysql5.7的時候報出一個警告,但是資料匯出成功:

 

現在換一種方式解決上述問題:

建立一my.cnf檔案,我放在與mysqldump.exe同級目錄下面:C:\Program Files\MySQL\MySQL Server 5.7\bin

[client]port = 3306socket = /tmp/mysql.sockdefault-character-set = utf8mb4host = localhostuser = rootpassword = ‘123456‘

 

重新匯出:(exam9為資料庫名字)

C:\Program Files\MySQL\MySQL Server 5.7>mysqldump --defaults-extra-file=my.cnf exam9 > e:/database.sql

 不會警示告:

 

 

 

二、匯出資料庫表結構

第一種:(警示告,但是執行成功!)

執行命令: mysqldump -hhostname -uusername -ppassword -d databasename > d:\sql\databasename.sql 

C:\Program Files\MySQL\MySQL Server 5.7>mysqldump -uroot -p123456 -d exam9 >e:/jiegou.sqlmysqldump: [Warning] Using a password on the command line interface can be insecure.

 

 

 第二種:(藉助上面的cnf檔案,不會警示告)

C:\Program Files\MySQL\MySQL Server 5.7>mysqldump --defaults-extra-file=my.cnf -d exam9 > e:/jiegou111.sqlC:\Program Files\MySQL\MySQL Server 5.7>

 

 

 

三、匯出資料庫表結構以及資料

第一種:(警示告,但是執行成功!)

C:\Program Files\MySQL\MySQL Server 5.7>mysqldump -uroot -p123456 -t exam9 >e:/shuju.sqlmysqldump: [Warning] Using a password on the command line interface can be insecure.

 

 第二種:(藉助上面的cnf檔案,不會警示告)

C:\Program Files\MySQL\MySQL Server 5.7\bin>mysqldump --defaults-extra-file=my.cnf -t exam9 > e:/shuju111.sqlC:\Program Files\MySQL\MySQL Server 5.7\bin>

 

 

 

四、匯出預存程序及函數

 

1、查詢資料庫中的預存程序和函數

    方法一:

    select `name` from mysql.proc where db = ‘databasename‘ and `type` = ‘PROCEDURE‘; // 預存程序
    select `name` from mysql.proc where db = ‘databasename‘ and `type` = ‘FUNCTION‘ // 函數

    方法二:

    show procedure status;
    show function status;

    

    2、mysql匯出預存程序及函數

    執行命令: mysqldump -hhostname -uusername -ppassword -ntd -R databasename > prorandfunc.sql

 

五、總結

-d 結構(--no-data:不匯出任何資料,只匯出資料庫表結構)


    -t 資料(--no-create-info:只匯出資料,而不添加CREATE TABLE 語句)


    -n (--no-create-db:只匯出資料,而不添加CREATE DATABASE 語句)


    -R (--routines:匯出預存程序以及自訂函數)


    -E (--events:匯出事件)


    --triggers (預設匯出觸發器,使用--skip-triggers屏蔽匯出)


    -B (--databases:匯出資料庫列表,單個庫時可省略)


    --tables 表列表(單個表時可省略)
    ①同時匯出結構以及資料時可同時省略-d和-t
    ②同時 不 匯出結構和資料可使用-ntd
    ③只匯出預存程序和函數可使用-R -ntd
    ④匯出所有(結構&資料&預存程序&函數&事件&觸發器)使用-R -E(相當於①,省略了-d -t;觸發器預設匯出)
    ⑤只匯出結構&函數&事件&觸發器使用 -R -E -d

 

MySQL匯出資料庫、資料庫表結構、預存程序及函數【用】

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.