Home | 簡體中文 | 繁體中文 | 雜文 | 知乎專欄 | Github | OSChina 博客 | 雲社區 | 雲棲社區 | Facebook | Linkedin | 視頻教程 | 打賞(Donations) | About
知乎專欄多維度架構

第 2 章 Client and Utility Programs

目錄

2.1. mysql - the MySQL command-line tool
2.1.1. ~/.my.cnf
2.1.2. 屏幕輸出到檔案
2.1.3. 終端編碼
2.1.4. Unix Socket
2.1.5. 重定向巧用
2.1.6. --sigint-ignore 忽略 Ctrl + C
2.2. mysqldump - a database backup program
2.2.1. 備份資料庫並壓縮檔案
2.2.2. 備份資料庫/表
2.2.3. 備份到檔案
2.2.4. 備份資料庫,無結構,只有數據
2.2.5. 使用完整的insert插入數據
2.2.6. --extended-insert / --skip-extended-insert
2.2.7. --skip-lock-tables
2.2.8. --skip-add-locks
2.2.9. --where
2.2.10. 註釋信息--comments /--skip-comments
2.2.11. 不導出註釋信息
2.2.12. 字符集設置
2.3. mysqladmin - client for administering a MySQL server
2.3.1. reload
2.3.2. 更改密碼
2.3.3. status
2.3.4. process list
2.4. myisamchk — MyISAM Table-Maintenance Utility
2.5. mysqlcheck — A Table Maintenance and Repair Program
2.6. mysqlslap - load emulation client
2.7. mysqldumpslow - Parse and summarize the MySQL slow query log.
2.8. mysql log

2.1. mysql - the MySQL command-line tool

2.1.1. ~/.my.cnf

# mysql_secure_installation config file
[mysql]

[mysqld]

[client]
user=root
password='chen'

[mysqldump]
quick

[mysqladmin]

[mysqlhotcopy]
			

2.1.2. 屏幕輸出到檔案

			
mysql>tee /home/neo/screen.txt
mysql>select * from member;
mysql>exit
			
			

2.1.3. 終端編碼

mysql> show variables like 'char%';
+--------------------------+----------------------------+
| Variable_name            | Value                      |
+--------------------------+----------------------------+
| character_set_client     | utf8                       |
| character_set_connection | utf8                       |
| character_set_database   | utf8                       |
| character_set_filesystem | binary                     |
| character_set_results    | utf8                       |
| character_set_server     | utf8                       |
| character_set_system     | utf8                       |
| character_sets_dir       | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.00 sec)
			

設置終端編碼 set names utf8;

mysql> select * from category;
+----+------+-------------+--------+-----------+-----------+
| id | name | description | status | parent_id | path      |
+----+------+-------------+--------+-----------+-----------+
|  1 | ??   | ???????     | Y      |      NULL | 1/        |
|  4 | ???  | ???         | Y      |         1 | 1/4       |
|  5 | ???  | NULL        | Y      |         4 | 1/4/5     |
|  6 | ???  | NULL        | Y      |         5 | 1/4/5/6   |
|  7 | ???  | NULL        | Y      |         6 | 1/4/5/6/7 |
+----+------+-------------+--------+-----------+-----------+
5 rows in set (0.00 sec)

mysql> set names utf8;
Query OK, 0 rows affected (0.00 sec)

mysql> select * from category;
+----+-----------+-----------------------+--------+-----------+-----------+
| id | name      | description           | status | parent_id | path      |
+----+-----------+-----------------------+--------+-----------+-----------+
|  1 | 中國    | 中華人民共和家                                    | Y      |      NULL | 1/        |
|  4 | 廣東省 | 廣東省                                                      | Y      |         1 | 1/4       |
|  5 | 深圳市 | NULL                      | Y      |         4 | 1/4/5     |
|  6 | 寶安區 | NULL                      | Y      |         5 | 1/4/5/6   |
|  7 | 龍華鎮 | NULL                      | Y      |         6 | 1/4/5/6/7 |
+----+-----------+-----------------------+--------+-----------+-----------+
5 rows in set (0.00 sec)

			

2.1.4. Unix Socket

mysql -uroot -p -S /tmp/mysql.sock
			

2.1.5. 重定向巧用

			
echo "show databases;" | mysql -uroot -pneo

cat |mysql -uroot -pneo << EOF
show databases;
EOF
			
			

2.1.6. --sigint-ignore 忽略 Ctrl + C

使用該選項方式用戶中途通過 Ctrl + C 推出,只能通過 quit 退出

$ mysql --sigint-ignore
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 71
Server version: 5.5.32-0ubuntu0.13.04.1 (Ubuntu)

Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> quit
Bye