Home | Mirror | Search

第 3 章 Client and Utility Programs

目錄

1. mysql - the MySQL command-line tool
1.1. ~/.my.cnf
1.2. 屏幕輸出到檔案
1.3. 終端編碼
1.4. Unix Socket
1.5. 重定向巧用
2. mysqldump - a database backup program
2.1. 備份資料庫,無結構,只有數據
2.2. 備份資料庫結構(不備份數據)
2.3. 使用完整的insert插入數據
2.4. --extended-insert / --skip-extended-insert
2.5. --where
3. mysqladmin - client for administering a MySQL server
3.1. reload
3.2. 更改密碼
3.3. status
3.4. process list
4. myisamchk — MyISAM Table-Maintenance Utility
5. mysqlcheck — A Table Maintenance and Repair Program
6. mysqlslap - load emulation client
7. mysqldumpslow - Parse and summarize the MySQL slow query log.
8. mysql log

1. mysql - the MySQL command-line tool

1.1. ~/.my.cnf

# mysql_secure_installation config file
[mysql]
user=root
password='chen'
			

1.2. 屏幕輸出到檔案

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

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)

			

1.4. Unix Socket

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

1.5. 重定向巧用

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

cat |mysql -uroot -pneo << EOF
show databases;
EOF
			
			
comments powered by Disqus