#新安裝mysql, 修改root密碼
mysqladmin -u root password 'rootpass'

#建立資料庫,名稱為db1
create database db1;

#建立使用者 webap
CREATE USER 'webap'@'localhost' IDENTIFIED BY 'webpass';

#讓 webap 有權限可以存取 db1
GRANT ALL ON db1.* TO 'webap'@'localhost';

#my.cnf 的路徑
/usr/local/libexec/mysqld --help --verbose

./libexec/mysqld Ver 5.5.44-MariaDB for FreeBSD9.3 on amd64 (FreeBSD Ports)
Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others.

Starts the MariaDB database server.

Usage: ./libexec/mysqld [OPTIONS]

Default options are read from the following files in the given order:
/usr/local/etc/my.cnf /usr/local/etc/mysql/my.cnf ~/.my.cnf

# innodb預設會將所有table的data及index儲存在ibdata1,時間一久這個檔案就會變得很大,建議可以將每個table分開儲存
1. 備份所有資料庫
mysqldump -u root -prootpw --all-databases > all-db.sql
2. 關閉mysql
mysqladmin -u root -prootpw shutdown
3. 編輯my.cnf
[mysqld]
innodb_file_per_table=1
4. rm ibdata1
5. 匯入資料庫
mysql -u root -prootpw < all-db.sql
6. 檢查檔案
確定每一個table是否有多出一個*.idb的檔案
table1.frm
table1.idb

# mysqldump 時讓每一筆record都是一個insert語法
mysqldump時預會把一個table裡面的資料塞成同一個insert語法,如果要讓每一筆紀錄都是一行insert時
加上 --skip-extended-insert 參數即可

#mysqldump 也可以下where 條件
example: mysqldump -u root -p mysql user --where="user='root'"

#某先狀況下,修改使用者權限,但未生效,可以重新載入權限
FLUSH PRIVILEGES ;

#動態修改mysql參數,但重啟後參數會恢復到預設值

SET GLOBAL character_set_database = 'utf8';
SET GLOBAL character_set_server = 'utf8';
SET GLOBAL collation_database = 'utf8_general_ci';
SET GLOBAL collation_server = 'utf8_general_ci';

# 鎖定資料表,防止寫入
FLUSH TABLES WITH READ LOCK;

# 解除鎖定
UNLOCK TABLES;

#mysqldump 但不包含某個table
 mysqldump -u root -p database_name --ignore-table=database_name.story

(未完成)

arrow
arrow
    文章標籤
    mysql
    全站熱搜

    helloworld 發表在 痞客邦 留言(0) 人氣()