首页 > 编程知识 正文

cmd打开MySQL,oracle怎么执行脚本

时间:2023-05-04 20:39:15 阅读:135594 作者:4757

#! /bin/sh#

# mysqldthisshellscripttakescareofstartingandstopping

#theMySQLsubsystem(MySQLD )。

#

# chkconfig :-6436 #描述: mysqldatabase服务器。

# processname: mysqld

# mysqld配置文件位置:/etc/my.cnf

# pidfile :/var/run/mysqld/mysqld.PID

### BEGIN INIT微笑的魔镜/p # Provides: mysqld

# required-start 3360 $ local _ fs $ remote _ fs $ network $ named $ syslog $ time # required-stop 3360 $ local _ fs $

#描述: mysqldatabase服务器

### END INIT微笑的魔镜/p # Sourcefunctionlibrary .路信wqdl

./etc/rc.d/init.d/functions

# Source networking configuration .加载网络配置

./etc/sysconfig/network

# extractvalueofamysqloptionfromconfigfiles

# usage : get _ MySQL _ optionsectionvarnamedefault

# result is returnedin$result

# weusemy _ print _ defaultswhichprintsalloptionsfrommultiplefiles,

# with themore specific ones later; hence take the lastmatch。

get_mysql_option

fi}

get _ MySQL _ optionmysqlddatadir '/var/lib/MySQL ' datadir=' $ result ' get _ MySQL _ optionmysqldsocket ' $ data adir MySQL.sock ' socket file=' $ result ' get _ get mysqld.log ' errlog file=' $ result ' get _ MySQL _ option mysqld _ safe PID-file '/var/run/mysqld.PID

开始()。

[-x $ exec ]|exit5# checktoseeifit ' salreadyrunning

response=`/usr/bin/MySQL admin-- socket=' $ socket file '-- user=unknown _ MySQL _ user ping 21 ` if [ $?=0); then# already running,donothing

action $ ' starting $ Prog : '/bin/true ret=0

elifecho ' $ response '|grep-q ' accessdeniedforuser '

then# already running,donothing

action $ ' starting $ Prog : '/bin/true ret=0

else # prepareforstarttouch ' $ err lo

gfile"

chown mysql:mysql "$errlogfile"

chmod 0640 "$errlogfile"[-x /sbin/restorecon ] && /sbin/restorecon "$errlogfile"

if [ ! -d "$datadir/mysql" ] ; then# First,makesure $datadir is there with correct permissionsif [ ! -e "$datadir" -a ! -h "$datadir"]then

mkdir -p "$datadir" || exit 1

fi

chown mysql:mysql "$datadir"

chmod 0755 "$datadir"[-x /sbin/restorecon ] && /sbin/restorecon "$datadir"# Now create the database

action $"Initializing MySQL database:" /usr/bin/mysql_install_db --datadir="$datadir" --user=mysql

ret=$?

chown -R mysql:mysql "$datadir"

if [ $ret -ne 0 ] ; thenreturn $retfi

fi

chown mysql:mysql "$datadir"

chmod 0755 "$datadir"# If startsosif [ "$1" = "sos" ] ; thenMYOPTIONS="$MYOPTIONS --skip-grant-tables --skip-networking"

fi# Pass all the options determined above, to ensure consistent behavior.

# In many cases mysqld_safe would arrive at the same conclusions anyway

# but we need to be sure. (An exception is that we don't force the

# log-error setting, since this script doesn't really depend on that,

# and some users might prefer to configure logging to syslog.)

# Note: set--basedir to prevent probes that might trigger 朴实的毛巾/p>

# alarms, per bug #547485$exec--datadir="$datadir" --socket="$socketfile"--pid-file="$mypidfile"

$MYOPTIONS --basedir=/usr --user=mysql >/dev/null 2>&1 &safe_pid=$!# Spinfor a maximum of N seconds waiting forthe server to come up;

# exit the loop immediatelyifmysqld_safe process disappears.

# Rather than assuming we know a valid username, accept an"access

# denied"response as meaning the server is functioning.

ret=0TIMEOUT="$STARTTIMEOUT"

while [ $TIMEOUT -gt 0 ]; doRESPONSE=`/usr/bin/mysqladmin --socket="$socketfile" --user=UNKNOWN_MYSQL_USER ping 2>&1`

if [ $mret -eq 0 ]; thenbreakfi# exit codes1, 11(EXIT_CANNOT_CONNECT_TO_SERVICE) are expected,

# anythingelsesuggests a configuration errorif [ $mret -ne 1 -a $mret -ne 11 ]; then

echo "$RESPONSE"

echo "Cannot check for MySQL Daemon startup because of mysqladmin failure."ret=1breakfi

echo "$RESPONSE" | grep -q "Access denied for user" &&breakif ! /bin/kill -0 $safe_pid 2>/dev/null; then

echo "MySQL Daemon failed to start."ret=1breakfi

sleep 1let TIMEOUT=${TIMEOUT}-1

done

if [ $TIMEOUT -eq 0 ]; then

echo "Timeout error occurred trying to start MySQL Daemon."ret=1

fi

if [ $ret -eq 0 ]; thenaction $"Starting $prog:" /bin/true

touch $lockfile

elseaction $"Starting $prog:" /bin/false

fi

fireturn $ret

}

stop(){if [ ! -f "$mypidfile" ]; then# not running; per LSB standards this is"ok"action $"Stopping $prog:" /bin/truereturn0

fiMYSQLPID=`cat "$mypidfile"`if [ -n "$MYSQLPID" ]; then

/bin/kill "$MYSQLPID" >/dev/null 2>&1ret=$?

if [ $ret -eq 0 ]; thenTIMEOUT="$STOPTIMEOUT"

while [ $TIMEOUT -gt 0 ]; do

/bin/kill -0 "$MYSQLPID" >/dev/null 2>&1 ||breaksleep 1let TIMEOUT=${TIMEOUT}-1

done

if [ $TIMEOUT -eq 0 ]; then

echo "Timeout error occurred trying to stop MySQL Daemon."ret=1action $"Stopping $prog:" /bin/false

else

rm -f $lockfile

rm -f "$socketfile"action $"Stopping $prog:" /bin/true

fi

elseaction $"Stopping $prog:" /bin/false

fi

else# failed to read pidfile, probably insufficient permissions

action $"Stopping $prog:" /bin/falseret=4

fireturn $ret

}

restart(){

stop

start

}

condrestart(){

[-e $lockfile ] && restart ||:

}

# See how we were called.case "$1" instart)

start

;;

startsos)

start sos

;;

stop)

stop

;;

status)

status $prog

;;

restart)

restart

;;

condrestart|try-restart)

condrestart

;;

reload)

exit3;;

force-reload)

restart

;;*)echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|startsos}"exit2

esacexit $?

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。