歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> 關於Linux >> thelinuxCommandLine學習筆記--mysql命令行導入sql文件到指定數據庫的方法

thelinuxCommandLine學習筆記--mysql命令行導入sql文件到指定數據庫的方法

日期:2017/3/1 13:38:48   编辑:關於Linux

中英文資料:http://billie66.github.io/TLCL/book/chap01.html

the graphical user interface (GUI) 圖形界面

The Command Line 命令行

Linux 是以 Unix 家族的操作系統為模型寫成的。

第二章 什麼是 Shell:
bash 是 shell 的一種,來自於 GNU 項目。“bash”是“Bourne Again SHell”的首字母縮寫,
所指的是這樣一個事實,bash 是 sh 的增強版,sh 是最初 Unix 的 shell 程序,
由 Steve Bourne 寫成。

KDE 用的是 konsole 程序, 而 GNOME 則使用 gnome-terminal。
還有其他一些終端仿真器可供 Linux 使用,但基本上,它們都是為了完成同樣的事情,
讓我們能訪問 shell

[me@linuxbox ~]$

“$" 普通用戶

a pound sign (“#”),提示符的最後一個字符是“#”, 而不是“$”, 那麼這個終端會話就有超級用戶權限。

命令歷史
查看以往的輸入的命令,向上箭頭

顯示系統當前時間和日期
[root@AY130410135131135089 ~]# date
Tue Nov 26 23:38:14 CST 2013

默認顯示當前月份的日歷
[root@AY130410135131135089 ~]# cal
November 2013
Su Mo Tu We Th Fr Sa
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30

查看磁盤剩余空間(free space on your disk drives)的數量,輸入 df:
[root@AY130410135131135089 ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/xvda1 20469760 7366592 13103168 36% /
tmpfs 1960828 0 1960828 0% /dev/shm

同樣地,顯示空閒內存的數量(the amount of free memory),輸入命令 free。
[root@AY130410135131135089 ~]# free
total used free shared buffers cached
Mem: 3921656 2141516 1780140 0 656 168692
-/+ buffers/cache: 1972168 1949488
Swap: 490488 2348 488140

結束終端會話,也即退出終端
[root@AY130410135131135089 ~]# exit
logout

第三章:
pwd - 打印當前所在目錄的名稱
cd  - 改變目錄
ls  - 打印目錄的內容
[root@AY130410135131135089 ~]# pwd
/root

Understanding The File System Tree理解文件系統樹
文件系統中的第一級目錄稱為根目錄

The Current Working Directory當前工作目錄
[root@AY130410135131135089 ~]# pwd
/root

Listing The Contents Of A Directory列出目錄內容
[root@AY130410135131135089 usr]# ls
bin etc games include lib lib64 libexec local sbin share src tmp

Changing The Current Working Directory更改當前工作目錄
從根目錄(用開頭的“/”表示)開始,有一個叫 “usr” 的 目錄包含了目錄 “bin”。
[root@AY130410135131135089 local]# cd /usr/bin/

符號 ”.” 指的是工作目錄,”..” 指的是工作目錄的父目錄。
經常使用 cd .. 返回上級目錄
cd ..
cd ../../..

cd 更改工作目錄到主目錄。
cd - 更改工作目錄到先前的工作目錄。
cd ~user_name 更改工作目錄到用戶主目錄。例如, cd ~bob 會更改工作目錄到用戶“bob”的主目錄
第四章:
ls 有一些我們常用的參數, 比如我們要知道當前目錄的所有內容, 包括隱藏文件夾和文件和所有屬性, 例
[root@AY130410135131135089 logs]# ls
boot2013-06.log

使用 ls 命令的“-l”選項,則結果以長模式輸出:
[root@AY130410135131135089 logs]# ls -l
total 8
-rw-rw-rw- 1 root root 5975 Jun 15 17:34 boot2013-06.log

顯示隱藏文件:
[root@AY130410135131135089 logs]# ls -a
. .. boot2013-06.log

命令 選項 參數
command -options arguments
下面這個例子,ls 命令有兩個選項, “l” 選項產生長格式輸出,“t”選項按文件修改時間的先後來排序。
[me@linuxbox ~]$ ls -lt


確定一個文件什麼文件類型我們用 file, 使用方法如下
[root@AY130410135131135089 logs]# file boot2013-06.log
boot2013-06.log: ASCII text

[root@AY130410135131135089 assets]# file world.swf
world.swf: Macromedia Flash data (compressed), version 10

用 less 浏覽文件內容
[me@linuxbox ~]$ less /etc/passwd
TODO 表 4-3: less 命令 需要截圖哦。

小提示:記得復制和粘貼技巧!如果你正在使用鼠標,雙擊文件名,來復制它,然後按下鼠標中鍵,粘貼文件名到命令行中。

Symbolic Links符號鏈接
Hard Links硬鏈接


第五章:操作文件和目錄
cp — 復制文件和目錄
mv — 移動/重命名文件和目錄
mkdir — 創建目錄
rm — 刪除文件和目錄

ln — 創建硬鏈接和符號鏈接 TODO沒搞懂 和Window快捷鍵的區別聯系 點擊打開鏈接

cp — 復制文件和目錄

jiangge@localhost:~$ cp item1 item2 # 把item復制到directory目錄

jiangge@localhost:~$ cp file1 file2 # 復制file1到file2

jiangge@localhost:~$ cp -i file1 file2 # 復制過程中如果有這個文件提示是否覆蓋

jiangge@localhost:~$ cp dir1/* dir2 # 復制目錄下所有文件或目錄到目標目錄

jiangge@localhost:~$ cp -r dir1 dir2 # 遞歸復制


mkdir — 創建目錄
jiangge@localhost:~$ mkdir dir

jiangge@localhost:~$ mkdir dir1 dir2 dir3 # 創建多個文件夾

jiangge@localhost:~$ mkdir -p /dir1/dir2/dir3 # 遞歸創建文件夾

mv — 移動/重命名文件和目錄
jiangge@localhost:~$ mv file1 file2 # 重命名

jiangge@localhost:~$ mv -i file1 file2 # 如果存在提示是否寫入

jiangge@localhost:~$ mv file1 file2 dir1 # 移動 file1 file2 至 dir1

jiangge@localhost:~$ mv dir1 dir2 # 移動 dir1 至 dir2


rm — 刪除文件和目錄
jiangge@localhost:~$ rm file1


jiangge@localhost:~$ rm file1 dir1

jiangge@localhost:~$ rm -r dir1 #刪除文件夾, 遞歸刪除

jiangge@localhost:~$ rm -rf dir1 強制刪除

表5-3:通配符范例
模式	匹配對象
*	所有文件
g*	文件名以“g”開頭的文件
b*.txt	以"b"開頭,中間有零個或任意多個字符,並以".txt"結尾的文件
Data???	以“Data”開頭,其後緊接著3個字符的文件
[abc]*	文件名以"a","b",或"c"開頭的文件
BACKUP.[0-9][0-9][0-9]	以"BACKUP."開頭,並緊接著3個數字的文件
[[:upper:]]*	以大寫字母開頭的文件
[![:digit:]]*	不以數字開頭的文件
*[[:lower:]123]	文件名以小寫字母結尾,或以 “1”,“2”,或 “3” 結尾的文件

表5-4:cp 選項
選項	意義
-a, --archive	復制文件和目錄,以及它們的屬性,包括所有權和權限。 通常,復本具有用戶所操作文件的默認屬性。
-i, --interactive	在重寫已存在文件之前,提示用戶確認。如果這個選項不指定, cp 命令會默認重寫文件。
-r, --recursive	遞歸地復制目錄及目錄中的內容。當復制目錄時, 需要這個選項(或者-a 選項)。
-u, --update	當把文件從一個目錄復制到另一個目錄時,僅復制 目標目錄中不存在的文件,或者是文件內容新於目標目錄中已經存在的文件。
-v, --verbose	顯示翔實的命令操作信息

表 5—5: cp 實例
命令	運行結果
cp file1 file2	復制文件 file1內容到文件 file2。如果 file2已經存在,file2的內容會被 file1的 內容重寫。如果 file2不存在,則會創建 file2。
cp -i file1 file2	這條命令和上面的命令一樣,除了如果文件 file2存在的話,在文件 file2被重寫之前, 會提示用戶確認信息。
cp file1 file2 dir1	復制文件 file1和文件 file2到目錄 dir1。目錄 dir1必須存在。
cp dir1/* dir2	使用一個通配符,在目錄 dir1中的所有文件都被復制到目錄 dir2中。 dir2必須已經存在。
cp -r dir1 dir2	復制目錄 dir1中的內容到目錄 dir2。如果目錄 dir2不存在, 創建目錄 dir2,操作完成後,目錄 dir2中的內容和 dir1中的一樣。 如果目錄 dir2存在,則目錄 dir1(和目錄中的內容)將會被復制到 dir2中。

第六章:點擊打開鏈接

type    - 解讀一個命令
which   - 顯示哪些是可執行程序,which 確定一個可執行程序的位置
man     - 顯示命令手冊
apropos - 顯示一個合適的命令列表
info    - 顯示一個命令信息
whatis  - 顯示非常簡短的描述一個命令
alias   - 為命令創建一個別名 
[shijiangge@localhost test]$ type type
type is a shell builtin
[shijiangge@localhost test]$ type ls
ls is aliased to `ls --color=tty'
[shijiangge@localhost test]$ type cp
cp is hashed (/bin/cp)
[shijiangge@localhost test]$ which ls #which 確定一個可執行程序的位置
alias ls='ls --color=tty'
        /bin/ls
[shijiangge@localhost test]$ which vim
/usr/bin/vim

help 獲得幫助信息, 在每個shell命令的後面加上--help參數, 如

[shijiangge@localhost test]$ ls --help
Usage: ls [OPTION]... [FILE]...
List information about the FILEs (the current directory by default).
Sort entries alphabetically if none of -cftuvSUX nor --sort.
[shijiangge@localhost test]$ help cd
cd: cd [-L|-P] [dir]
     Change the current directory to DIR.  The variable $HOME is the
    default DIR.  

注意表示法:出現在命令語法說明中的方括號,表示可選的項目。一個豎槓字符 表示互斥選項。在上面 cd 命令的例子中:
cd [-L|-P] [dir]

這種表示法說明,cd 命令可能有一個”-L”選項或者”-P”選項,進一步,可能有參數”dir”。

man 獲得命令指南

[shijiangge@localhost test]$ man ls 

whatis 顯示一個簡短的描述

[shijiangge@localhost test]$ whatis ls
ls                   (1)  - list directory contents
ls                   (1p)  - list directory contents
[shijiangge@localhost test]$ whatis vim
vim                  (1)  - Vi IMproved, a programmers text editor 

用別名(alias)創建你自己的命令

shijiangge@localhost:~$ type test
test is a shell builtin

shijiangge@localhost:~$ type foo
/bin/bash: line 0: type: foo: not found      # 什麼都沒有

shijiangge@localhost:~$ alias foo='cd /usr; ls; cd -'

shijiangge@localhost:~$ alias name='string'

shijiangge@localhost:~$ alias                         # 創建de自定義命令都打印出來
alias foo='cd /usr; ls; cd -'
alias name='string'

shijiangge@localhost:~$ foo
bin include lib local man sbin share src
/home/shijiangge

shijiangge@localhost:~$ type foo
foo is aliased to 'cd /usr; ls; cd -'

shijiangge@localhost:~$ unalias foo                   # 銷毀foo

shijiangge@localhost:~$ alias                         # 只剩下name了
alia name='string'

shijiangge@localhost:~$ type foo                      # 什麼都沒有
/bin/bash: foo: command not found

shijiangge@localhost:~$ unalias name                  # 銷毀name 
TODO第七章

==========================================

Lunix 調整時間,就是將服務器時間調快或調慢,線上一般不要調整時間,本地為了測試在調整服務器時間的。


date -s 07/09/2013
date -s 17:05:00


==========================================
mysql命令行導入sql文件到指定數據庫的方法


mysql命令行導入的方式。
以下是各步驟:


1、先將數據庫通過ftp上傳至服務器內
或者使用 rz -y 進行上傳

2、登陸mysql數據庫:
mysql -u root -p

3、選擇數據庫:

use mydbname;

4、導入文件:

[win下] source e:\newdb.sql;


[linux下] source /root/newdb.sql;


導入成功!

==============================================
再來一個導出的吧(不用在mysql命令行):
mysqldump -uroot -p dbname table1 table2 > foo.sql

mysqldump -uroot -p huo > /usr/local/jiangge/foo.sql

壓縮:
zip -r webgames.zip webgames

===================================================
FTP--ftp 啟動命令:
service vsftpd start

----------------------------------------------------------------------------------

Copyright © Linux教程網 All Rights Reserved