Linux mysql shell script position parameters and environmental variables predefined variables for operator process control loop with the determined user interaction function

mysql

1. Uninstall the old version

-qa RPM | grep checks for older versions of MySQL 

query results: MySQL -libs-5.1.73-7 .el6.x86_64 

RPM -e mysql- libs remove the old version of the 
RPM -e MySQL-libs - nodeps forcibly removed

2. Install mysql

2.1 installation source needs to be compiled

Download c compiler tool 
yum -y install the make gcc-c ++ cmake Bison-devel ncurses-devel

2.2 xftp connection to upload

Upload xftp connected to opt folder

2.3 compiler

1. tar -zxvf mysql-5.6.14.tar.gz        解压
2. cd mysql-5.6.14                        切换目录

3.编译准备:
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -
DMYSQL_DATADIR=/usr/local/mysql/data -DSYSCONFDIR=/etc -
DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -
DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -
DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock -DMYSQL_TCP_PORT=3306 -DENABLED_LOCAL_INFILE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -
DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci 编译并安装: make && make install

2.4 Configuration mysql

1 . Create mysql groups, and users 
    the groupadd mysql 
    the useradd - G mysql mysql 
    the passwd mysql
 2 initialization configuration:
 1.CD / usr / local / mysql
 2.scripts / the mysql_install_db

 . 3 modify permissions: 
Modify / usr / local / mysql permissions 
chown MySQL -R: MySQL / usr / local / MySQL

 4. when you start MySQL service will first find my.cnf in / etc directory, search will not find " $ basedir / my.cnf " , in this case, is / usr / local / MySQL / my.cnf 
to see / if there my.cnf under etc, have to change the name to prevent interference 
mv /usr/local/mysql/my.cnf / usr / local / MySQL / my.cnf. BAK

 5. The added service (mysql service into the / etc /init.d), and set the boot from the start:
 1.CP /usr/local/mysql/support-files/mysql.server /etc/init.d/ MySQL
 2 .chkconfig MySQL ON
 . 3 .service MySQL Start

 . 6 . Configuration Environment variables:
 1.vi / etc / Profile
 2 was added in the file:. 
    Export the PATH = / usr / local / MySQL / bin: $ the PATH
 3.source / etc / Profile

shell programming

1.shell programming is Gesha

Shell is a command line interpreter, which provides a system level application program sends a request to run the Linux kernel for the user

2.shell programming print hello world use cases

1. Create a new script file (ending bash)

vim hello.sh

2. The script file coding

#!/bin/bash
echo 'hello world'

Code explanation:

1.#!/bin/bash:

Tells the computer, use the bash interpreter to execute code

2.echo:

Console output

3. Run the script file

:( a way not recommended)

Directly call shell interpreter to execute

1 .hello.sh file path 
bash hello.sh

Second way:

Executable permission to the script

1 .hello.sh file path 
chmod 744 hello.sh

 2. file path runs directly 
./hello.sh

 

 

 3. Comment

1 . Single-line comments
 # content
 
2 . Multiline comments 
: << ! 
Content 
!

variable

Introduction 1. Variables

1.Linux in classification variables: system variables (system previously defined) Custom Variable 
2. reference variable: $ variable name
3. System variables: $ the PATH $ the HOME $ PWD $ SHELL $ the USER 4. display all the current shell variable: set

2. The definition of a variable

1. Define the variable: variable name = variable value
 2 revoked variables:. Unset variable name
 3. static variable declaration: Readonly = variable name and the value of static variables can change value unset

Defined rules

1 Variable names can consist of letters, digits, and underscores, but can not start with a number
 2 on both sides of the equal sign can not have spaces
 3. The general custom variable name to uppercase

3. The command returns the value to the variable (a plurality)

LS = `1.A - la` Backticks, which run command, and returns the result to the variable A
 2.A = $ (LS -la) equivalent to backticks

Set Environment Variables

The basic syntax

1.export variable name = variable value output to shell variable environment variable
 2 .source profile allows configuration changes take effect immediately after
 the value of the variable value View 3.echo $ environment variable

Location parameter variables (pass parameters to the executable file)

When we execute a shell script, if you want to get information about the command-line parameters, you can use the position parameter variables

The basic syntax

. 1 . 
$ N-(Function Description: n = number, $ 0 for the command itself, $ 1- $ 9 represents a first parameter to the ninth, ten or more parameters, the parameters need to include ten or more braces, such as $ {10 } )

 2 . 
$ * (functional description: this variable represents all of the command line parameters, $ * all the parameters as a whole)

 3 . 
$ @ (function description: this variable also represents all of the command line parameters, but $ @ parameters to each treated differently)

 4 . 
$ # (functional description: this variable represents the command line parameters for all the number)

Predefined variables

Designers shell is already pre-defined variables, you can directly use shell scripts

The basic syntax

$$ (Functional Description: The current process process ID (PID)) $ 
(Function Description: Process number of the last process running in the background (PID))! $ 
(Function return the result to obtain) (Function Description:? Last execution return to command state if this variable is 0, prove that the last command executed correctly; If the value of this variable is non-zero (which specific numbers, to decide the order), then the proof on a command fails)

Operators

The basic syntax

1 $ ((expression)).
 2 $ [expression] ------. Recommended
 m + 3.`expr n` within the 
    features: there must be a space between the operators
     + 
    - 
    / 
    % 
    \ * 
    \ (\ )

Judge

The basic syntax

[Condition] Note: conditions include a space before and after 

special: 
[non-empty] is to true 
[] is false 
[haha] && echo echo false to true ||

1. string comparison

=     Equality has to
 ! = Not equal sentence

2. Compare Integer

- lt smaller than
 - Le less
 - gt larger than
 - GE greater than or equal
 - EG equal
 -ne not equal

3. File permissions judge

-r have permission to read [- r file]
 -w have the authority to write [- w file path]
 -x Executive authority
-f file exists and is generally [- F File]
 - the presence of (a plurality) e file
 -d exists and is a directory

Process Control

1. Basic grammar

. 1 .
 IF [Condition] 
the then 
    codes 
fi

 2 .
 IF [Condition] 
the then 
    codes 
else 
    Code 
fi

 . 3 .
 IF [Condition] 
the then 
    codes 
elif [Condition] 
the then 
    codes 
else 
    Code 
fi

2.case alternative branch

case $ variable name in 
' value 1 ' ) 
Code 
;; 
' value 2 ' ) 
Code 
;;
 * ) 
Code execution did not hit 
;; 
esac

for loop

1. Use a

for ((initial value; Cycling conditions; additional conditions)) 
do 
    Code 
done

2. Usage of Two

for the variable in the value of the binary value 1. 3 
do 
    codes 
done

while loop

the while [Condition] 
do 
    codes 
done

Interaction with the user

The basic syntax

read options Variable 
Option:
 - the p-: prompt
 -t: waiting for input time

function

1. System functions

basename

basename [pathname] [suffix] 
to obtain the final part of the path 

if the specified suffix, then the result will be removed in portions suffix

dirname

dirname [pathname] 
obtained base path

2. Custom Functions

No parameter

function name of the function () { 
    Code; 
    # parameters: $ 1, $ 2, ..., 10} $ {... 
    return XXX; 
} 

return result will be captured by whom: $? 

call: 
the function name value value 1 2

Guess you like

Origin www.cnblogs.com/tfzz/p/12075235.html