ThelinuxCommandLine learning notes -- mysql Command Line Method for importing SQL files to a specified database

Source: Internet
Author: User
Tags superuser permission


The graphical user interface (GUI) graphical interface

The Command Line

Linux is written based on the operating system of the Unix family.

Chapter 2 What is Shell:
Bash is a type of shell from the GNU project. "Bash" is the abbreviation of "Bourne Again SHell,
It refers to the fact that bash is an enhanced version of sh, and sh is the original Unix shell program,
Written by Steve Bourne.

KDE uses the konsole program, while GNOME uses gnome-terminal.
There are also some other terminal simulators available for Linux, but basically they are all for the same purpose,
Let's access shell

[Me @ linuxbox ~] $

"$" Common User

A pound sign ("#"), the last character of the prompt is "#", rather than "$", so this terminal session has the superuser permission.

Command history
View previous commands and click the Up Arrow

Displays the current system time and date.
[Root @ ay1301_135131135089 ~] # Date
Tue Nov 26 23:38:14 CST 2013

The calendar of the current month is displayed by default.
[Root @ ay1301_135131135089 ~] # 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

View remaining disk space(Free space on your disk drives), input df:
[Root @ ay1301_135131135089 ~] # Df
Filesystem 1K-blocks Used Available Use % Mounted on
/Dev/xvda1 20469760 7366592 13103168 36%/
Tmpfs 1960828 0 1960828 0%/dev/shm

Similarly, Number of idle memory(The amount of free memory), enter the command free.
[Root @ ay1301_135131135089 ~] # Free
Total used free shared buffers cached
Mem: 3921656 2141516 1780140 0 656 168692
-/+ Buffers/cache: 1972168 1949488
Swap: 490488 2348 488140

End the terminal session, that is Exit Terminal
[Root @ ay1301_135131135089 ~] # Exit

Chapter 3:
Pwd-print the name of the current directory cd-Change directory ls-print directory content
[Root @ ay1301_135131135089 ~] # Pwd

Understanding The File System Tree Understanding the file system tree
The first directory in the file system is called the root directory.

The Current Working Directory Current working directory
[Root @ ay1301_135131135089 ~] # Pwd

Listing The Contents Of A Directory List Directory content
[Root @ ay1301_135131135089 usr] # ls
Bin etc games include lib lib64 libexec local sbin share src tmp

Changing The Current Working Directory Change current working directory
Starting from the root directory (represented by "/" at the beginning), there is a directory named "usr" that contains the directory "bin ".
[Root @ ay1301_135131135089 local] # cd/usr/bin/

Symbol "." refers to the working directory, "..." refers to the parent directory of the working directory.
Frequent use of cd .. back to parent directory
Cd ..
Cd ../../..

Cd to change the working directory to the main directory.
Cd-change the working directory to the previous working directory.
Cd ~ User_name: change the working directory to the user's home directory. For example, cd ~ Bob will change the working directory to the main directory of user "bob ".
Chapter 4:
Ls has some common parameters. For example, we need to know all the contents of the current directory, including hiding folders and files and all attributes. For example
[Root @ ay1301_135131135089 logs] # ls

Use the ls command -L Option, The result is output in Long Mode:
[Root @ ay1301_135131135089 logs] # ls-l
Total 8
-Rw-1 root 5975 Jun 15 :34 boot2013-06.log

Show Hidden Files:
[Root @ ay1301_135131135089 logs] # ls-
... Boot2013-06.log

Command Option Parameters
Command-options arguments
In the following example, the ls command has two options: the "l" option produces long format output, "T" option by file modification time.
[Me @ linuxbox ~] $ Ls-lt

Determine the file type of a fileUse file as follows:
[Root @ ay1301_135131135089 logs] # file boot2013-06.log
Boot2013-06.log: ASCII text.

[Root @ ay1301_135131135089 assets] # file world.swf
World.swf: Macromedia Flash data (compressed), version 10

Use less to Browse File Content
[Me @ linuxbox ~] $ Less/etc/passwd
TODO Table 4-3: less command is required.

Tip: Remember to copy and paste it! If you are using the mouse, double-click the file name to copy it, and then press the middle mouse button to paste the file name to the command line.

Symbolic Links Symbolic Link
Hard Links

Chapter 5: Operating Files And Directories
Cp-copy files and directories mv-move/rename files and directories mkdir-create directories rm-delete files and directories

Ln-I didn't understand the difference between creating a hard link and a symbolic link TODO and the Window shortcut key.

Cp-copy files and directories

Jiangge @ localhost :~ $ Cp item1 item2 # copy an item to the directory

Jiangge @ localhost :~ $ Cp file1 file2 # copy file1 to file2

Jiangge @ localhost :~ $ Cp-I file1 file2 # if this file exists during the copy process, it indicates whether to overwrite the file.

Jiangge @ localhost :~ $ Cp dir1/* dir2 # copy all files or directories in the directory to the target directory

Jiangge @ localhost :~ $ Cp-r dir1 dir2 # recursive Replication

Mkdir-create a directory
Jiangge @ localhost :~ $ Mkdir dir

Jiangge @ localhost :~ $ Mkdir dir1 dir2 dir3 # create multiple folders

Jiangge @ localhost :~ $ Mkdir-p/dir1/dir2/dir3 # recursively create a folder

Mv-move/rename files and directories
Jiangge @ localhost :~ $ Mv file1 file2 # rename

Jiangge @ localhost :~ $ Mv-I file1 file2 # if there is a prompt whether to write

Jiangge @ localhost :~ $ Mv file1 file2 dir1 # Move file1 file2 to dir1

Jiangge @ localhost :~ $ Mv dir1 dir2 # Move dir1 to dir2

Rm-delete files and directories
Jiangge @ localhost :~ $ Rm file1

Jiangge @ localhost :~ $ Rm file1 dir1

Jiangge @ localhost :~ $ Rm-r dir1 # delete a folder and recursively delete it

Jiangge @ localhost :~ $ Rm-rf dir1 force Delete


Table 5-3: wildcard example matching object * all file g * file names start with "g" file B *. txt starts with "B", contains zero or any number of characters in the middle, and starts ". txt "End file Data ??? File names starting with "Data" and followed by three characters [abc] * BACKUP files whose names start with "a", "B", or "c. [0-9] [0-9] [0-9] To "BACKUP. "followed by three numbers: [[: upper:] * files starting with an uppercase letter [! [: Digit:] * a file not starting with a number * [[: lower:] 123] the file name ends with a lowercase letter or ends with "1", "2 ", or a file ending with "3"


Table 5-4: cp option meaning-a, -- archive copy files and directories, and their attributes, including ownership and permissions. Normally, a duplicate has the default attribute of the file to be operated by the user. -I, -- interactive prompts the user to confirm before rewriting an existing file. If this option is not specified, the cp command will overwrite the file by default. -R, -- recursive Recursively copies contents in directories and directories. This option is required when you copy a directory (or-). -U, -- update: When a file is copied from one directory to another, only the files that do not exist in the target directory are copied, or the file content is new to the existing files in the target directory. -V, -- verbose displays detailed command operation information

Table 5-5: cp instance Command run result cp file1 file2 copy file file1 content to file file2. If file2 already exists, the content of file2 will be overwritten by the content of file1. If file2 does not exist, file2 is created. The cp-I file1 file2 command is the same as the preceding command. Except for the existence of file file2, you are prompted to confirm the information before file file2 is overwritten. Cp file1 file2 dir1: Copy file1 and file2 to the directory dir1. The directory dir1 must exist. Cp dir1/* dir2 uses a wildcard. All files in the dir1 directory are copied to the dir2 directory. Dir2 must already exist. Copy the contents in the dir1 directory to the dir2 directory. If the directory dir2 does not exist, create the directory dir2. After the operation is complete, the contents in the directory dir2 are the same as those in dir1. If the directory dir2 exists, the directory dir1 (and the content in the directory) will be copied to dir2.

Chapter 6: Click the open link

Type-interpret a command which-show which programs are executable, which determines the location of an executable program man-display command manual apropos-display an appropriate command List info-display a Command Information whatis-display a very brief description of a command alias-for the command create an alias
[shijiangge@localhost test]$ type typetype is a shell builtin
[shijiangge@localhost test]$ type lsls is aliased to `ls --color=tty'
[shijiangge@localhost test]$ type cpcp is hashed (/bin/cp)
[Shijiangge @ localhost test] $ which ls # which determines the location of an executable program alias ls = 'ls -- color = tty '/bin/ls
[shijiangge@localhost test]$ which vim/usr/bin/vim

Help to get help information. Add the -- help parameter after each shell command, as shown in figure

[shijiangge@localhost test]$ ls --helpUsage: 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 cdcd: cd [-L|-P] [dir]     Change the current directory to DIR.  The variable $HOME is the    default DIR.  

Note: square brackets appear in the command syntax description to indicate optional items. A vertical bar character indicates the mutex option. In the example of the cd command above:
Cd [-L |-P] [dir]

This notation indicates that the cd command may have a "-L" option or "-P" option. Further, the "dir" parameter may exist ".

Man command Guide

[shijiangge@localhost test]$ man ls 

Whatis displays a brief description

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

Use an alias (alias) to create your own commands

Shijiangge @ localhost :~ $ Type testtest is a shell builtinshijiangge @ localhost :~ $ Type foo/bin/bash: line 0: type: foo: not found # No shijiangge @ localhost :~ $ Alias foo = 'CD/usr; ls; cd-'shijiangge @ localhost :~ $ Alias name = 'string' shijiangge @ localhost :~ $ Alias # print all the created de custom commands alias foo = 'CD/usr; ls; cd-'Alias name = 'string' shijiangge @ localhost :~ $ Foobin include lib local man sbin share src/home/shijianggeshijiangge @ localhost :~ $ Type foofoo is aliased to 'CD/usr; ls; cd-'shijiangge @ localhost :~ $ Unalias foo # destroy fooshijiangge @ localhost :~ $ Alias # Only the name is left. alia name = 'string' shijiangge @ localhost :~ $ Type foo # Nothing/bin/bash: foo: command not foundshijiangge @ localhost :~ $ Unalias name # destroy name
Chapter 7 of TODO

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

The Lunix adjustment time is to speed up or slow down the server time. Generally, do not adjust the time online. To test locally, adjust the server time.

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

========================================================== =
How to import an SQL file to a specified database through the mysql Command Line

Mysql command line import method.
The steps are as follows:

1. First upload the database to the server through ftp
Or use rz-y for upload.

2. log on to the mysql database:
Mysql-u root-p

3. Select a database:

Use mydbname;

4. Import files:

[Win] source e: \ newdb. SQL;

[In linux] source/root/newdb. SQL;

Import successful!

========================================================== ======
Let's try to export it again (without using the mysql Command Line ):
Mysqldump-uroot-p dbname table1 table2> foo. SQL

Mysqldump-uroot-p huo>/usr/local/jiangge/foo. SQL

Zip-r webgames

========================================================== ==============
FTP -- ftp startup command:
Service vsftpd start


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.