Skip to content

Instantly share code, notes, and snippets.

@ankion
Last active August 29, 2015 14:03
Show Gist options
  • Select an option

  • Save ankion/a4f4a0c8b1942e202017 to your computer and use it in GitHub Desktop.

Select an option

Save ankion/a4f4a0c8b1942e202017 to your computer and use it in GitHub Desktop.

Revisions

  1. ankion revised this gist Jul 15, 2014. 1 changed file with 21 additions and 1 deletion.
    22 changes: 21 additions & 1 deletion gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -17,4 +17,24 @@ Query OK, 0 rows affected (0.01 sec)

    mysql> EXIT
    Bye
    $
    $

    -- 備份某個資料庫

    # mysqldump -u root -p db_name > backup.sql;

    -- 備份資料庫中的某個資料表

    # mysqldump -u root -p db_name table_name > backup.sql;

    -- 備份所有資料庫

    # mysqldump -u root -p --all-databases > backup.sql;

    -- 復原一個資料庫 (需先建好db_name 這個資料庫, 若沒建立請先執行 mysqladmin create db_name 建立即可)

    # mysql -u root -p db_name < backup.sql

    -- 復原多個資料庫 ( 因為backup.sql 內已有 CREATE DATABASE指令,因此不需先建DB)

    # mysql -u root -p < backup.sql
  2. ankion created this gist Jul 11, 2014.
    20 changes: 20 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    $ mysql -u adminusername -p
    Enter password:
    Welcome to the MySQL monitor. Commands end with ; or \g.
    Your MySQL connection id is 5340 to server version: 3.23.54

    Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

    mysql> CREATE DATABASE databasename;
    Query OK, 1 row affected (0.00 sec)

    mysql> GRANT ALL PRIVILEGES ON databasename.* TO "wordpressusername"@"hostname"
    -> IDENTIFIED BY "password";
    Query OK, 0 rows affected (0.00 sec)

    mysql> FLUSH PRIVILEGES;
    Query OK, 0 rows affected (0.01 sec)

    mysql> EXIT
    Bye
    $