diff options
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/mysql_setpermission.sh | 22 | ||||
-rw-r--r-- | scripts/mysql_system_tables.sql | 21 | ||||
-rw-r--r-- | scripts/mysqld_safe.sh | 116 |
3 files changed, 112 insertions, 47 deletions
diff --git a/scripts/mysql_setpermission.sh b/scripts/mysql_setpermission.sh index 9699cd28047..1f5509f9955 100644 --- a/scripts/mysql_setpermission.sh +++ b/scripts/mysql_setpermission.sh @@ -19,13 +19,14 @@ ## 1.3 Applied patch provided by Martin Mokrejs <mmokrejs@natur.cuni.cz> ## (General code cleanup, use the GRANT statement instead of updating ## the privilege tables directly, added option to revoke privileges) +## 1.4 Remove option 6 which attempted to erroneously grant global privileges #### TODO # # empty ... suggestions ... mail them to me ... -$version="1.3"; +$version="1.4"; use DBI; use Getopt::Long; @@ -103,13 +104,9 @@ sub q1 { # first question ... print " existing database and host combination (user can do\n"; print " SELECT,INSERT,UPDATE,DELETE,CREATE,DROP,INDEX,\n"; print " LOCK TABLES,CREATE TEMPORARY TABLES)\n"; - print " 6. Create/append database administrative privileges for an\n"; - print " existing database and host combination (user can do\n"; - print " SELECT,INSERT,UPDATE,DELETE,CREATE,DROP,INDEX,LOCK TABLES,\n"; - print " CREATE TEMPORARY TABLES,SHOW DATABASES,PROCESS)\n"; - print " 7. Create/append full privileges for an existing database\n"; + print " 6. Create/append full privileges for an existing database\n"; print " and host combination (user has FULL privilege)\n"; - print " 8. Remove all privileges for for an existing database and\n"; + print " 7. Remove all privileges for for an existing database and\n"; print " host combination.\n"; print " (user will have all permission fields set to N)\n"; print " 0. exit this program\n"; @@ -117,10 +114,10 @@ sub q1 { # first question ... while (<STDIN>) { $answer = $_; chomp($answer); - if ($answer =~ /^[12345678]$/) { + if ($answer =~ /^[1234567]$/) { if ($answer == 1) { setpwd(); - } elsif ($answer =~ /^[2345678]$/) { + } elsif ($answer =~ /^[234567]$/) { addall($answer); } else { print "Sorry, something went wrong. With such option number you should not get here.\n\n"; @@ -233,7 +230,7 @@ sub addall { } } - if ( ( !$todo ) or not ( $todo =~ m/^[2-8]$/ ) ) { + if ( ( !$todo ) or not ( $todo =~ m/^[2-7]$/ ) ) { print STDERR "Sorry, select option $todo isn't known inside the program .. See ya\n"; quit(); } @@ -256,12 +253,9 @@ sub addall { # user privileges: SELECT,INSERT,UPDATE,DELETE,CREATE,DROP,INDEX,LOCK TABLES,CREATE TEMPORARY TABLES $sth = $dbh->do("GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP,INDEX,LOCK TABLES,CREATE TEMPORARY TABLES ON $db.* TO $user@\"$host\" IDENTIFIED BY \'$pass\'") || die $dbh->errstr; } elsif ($todo == 6) { - # admin privileges: GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP,INDEX,LOCK TABLES,CREATE TEMPORARY TABLES,SHOW DATABASES,PROCESS - $sth = $dbh->do("GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP,INDEX,LOCK TABLES,CREATE TEMPORARY TABLES,SHOW DATABASES,PROCESS ON $db.* TO $user@\"$host\" IDENTIFIED BY \'$pass\'") || die $dbh->errstr; - } elsif ($todo == 7) { # all privileges $sth = $dbh->do("GRANT ALL ON $db.* TO \'$user\'\@\'$host\' IDENTIFIED BY \'$pass\'") || die $dbh->errstr; - } elsif ($todo == 8) { + } elsif ($todo == 7) { # all privileges set to N $sth = $dbh->do("REVOKE ALL ON *.* FROM \'$user\'\@\'$host\'") || die $dbh->errstr; } diff --git a/scripts/mysql_system_tables.sql b/scripts/mysql_system_tables.sql index f46c7c7027a..cd0882e3af4 100644 --- a/scripts/mysql_system_tables.sql +++ b/scripts/mysql_system_tables.sql @@ -63,16 +63,21 @@ CREATE TABLE IF NOT EXISTS proc (db char(64) collate utf8_bin DEFAULT '' NOT NUL CREATE TABLE IF NOT EXISTS procs_priv ( Host char(60) binary DEFAULT '' NOT NULL, Db char(64) binary DEFAULT '' NOT NULL, User char(16) binary DEFAULT '' NOT NULL, Routine_name char(64) binary DEFAULT '' NOT NULL, Routine_type enum('FUNCTION','PROCEDURE') NOT NULL, Grantor char(77) DEFAULT '' NOT NULL, Proc_priv set('Execute','Alter Routine','Grant') COLLATE utf8_general_ci DEFAULT '' NOT NULL, Timestamp timestamp(14), PRIMARY KEY (Host,Db,User,Routine_name,Routine_type), KEY Grantor (Grantor) ) engine=MyISAM CHARACTER SET utf8 COLLATE utf8_bin comment='Procedure privileges'; +-- Create general_log if CSV is enabled. -delimiter ;; -CREATE PROCEDURE create_general_log_table() BEGIN DECLARE is_csv_enabled int DEFAULT 0; SELECT @@have_csv = 'YES' INTO is_csv_enabled; IF (is_csv_enabled) THEN CREATE TABLE IF NOT EXISTS general_log (event_time TIMESTAMP NOT NULL, user_host MEDIUMTEXT, thread_id INTEGER, server_id INTEGER, command_type VARCHAR(64), argument MEDIUMTEXT) engine=CSV CHARACTER SET utf8 comment='General log'; END IF; END;; -CALL create_general_log_table();; -DROP PROCEDURE create_general_log_table;; +SET @str = IF (@@have_csv = 'YES', 'CREATE TABLE IF NOT EXISTS general_log (event_time TIMESTAMP NOT NULL, user_host MEDIUMTEXT, thread_id INTEGER, server_id INTEGER, command_type VARCHAR(64), argument MEDIUMTEXT) engine=CSV CHARACTER SET utf8 comment="General log"', 'SET @dummy = 0'); -CREATE PROCEDURE create_slow_log_table() BEGIN DECLARE is_csv_enabled int DEFAULT 0; SELECT @@have_csv = 'YES' INTO is_csv_enabled; IF (is_csv_enabled) THEN CREATE TABLE IF NOT EXISTS slow_log (start_time TIMESTAMP NOT NULL, user_host MEDIUMTEXT NOT NULL, query_time TIME NOT NULL, lock_time TIME NOT NULL, rows_sent INTEGER NOT NULL, rows_examined INTEGER NOT NULL, db VARCHAR(512), last_insert_id INTEGER, insert_id INTEGER, server_id INTEGER, sql_text MEDIUMTEXT NOT NULL) engine=CSV CHARACTER SET utf8 comment='Slow log'; END IF; END;; -CALL create_slow_log_table();; -DROP PROCEDURE create_slow_log_table;; -delimiter ; +PREPARE stmt FROM @str; +EXECUTE stmt; +DROP PREPARE stmt; + +-- Create slow_log if CSV is enabled. + +SET @str = IF (@@have_csv = 'YES', 'CREATE TABLE IF NOT EXISTS slow_log (start_time TIMESTAMP NOT NULL, user_host MEDIUMTEXT NOT NULL, query_time TIME NOT NULL, lock_time TIME NOT NULL, rows_sent INTEGER NOT NULL, rows_examined INTEGER NOT NULL, db VARCHAR(512), last_insert_id INTEGER, insert_id INTEGER, server_id INTEGER, sql_text MEDIUMTEXT NOT NULL) engine=CSV CHARACTER SET utf8 comment="Slow log"', 'SET @dummy = 0'); + +PREPARE stmt FROM @str; +EXECUTE stmt; +DROP PREPARE stmt; CREATE TABLE IF NOT EXISTS event ( db char(64) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL default '', name char(64) CHARACTER SET utf8 NOT NULL default '', body longblob NOT NULL, definer char(77) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL default '', execute_at DATETIME default NULL, interval_value int(11) default NULL, interval_field ENUM('YEAR','QUARTER','MONTH','DAY','HOUR','MINUTE','WEEK','SECOND','MICROSECOND','YEAR_MONTH','DAY_HOUR','DAY_MINUTE','DAY_SECOND','HOUR_MINUTE','HOUR_SECOND','MINUTE_SECOND','DAY_MICROSECOND','HOUR_MICROSECOND','MINUTE_MICROSECOND','SECOND_MICROSECOND') default NULL, created TIMESTAMP NOT NULL, modified TIMESTAMP NOT NULL, last_executed DATETIME default NULL, starts DATETIME default NULL, ends DATETIME default NULL, status ENUM('ENABLED','DISABLED','SLAVESIDE_DISABLED') NOT NULL default 'ENABLED', on_completion ENUM('DROP','PRESERVE') NOT NULL default 'DROP', sql_mode set('REAL_AS_FLOAT','PIPES_AS_CONCAT','ANSI_QUOTES','IGNORE_SPACE','NOT_USED','ONLY_FULL_GROUP_BY','NO_UNSIGNED_SUBTRACTION','NO_DIR_IN_CREATE','POSTGRESQL','ORACLE','MSSQL','DB2','MAXDB','NO_KEY_OPTIONS','NO_TABLE_OPTIONS','NO_FIELD_OPTIONS','MYSQL323','MYSQL40','ANSI','NO_AUTO_VALUE_ON_ZERO','NO_BACKSLASH_ESCAPES','STRICT_TRANS_TABLES','STRICT_ALL_TABLES','NO_ZERO_IN_DATE','NO_ZERO_DATE','INVALID_DATES','ERROR_FOR_DIVISION_BY_ZERO','TRADITIONAL','NO_AUTO_CREATE_USER','HIGH_NOT_PRECEDENCE') DEFAULT '' NOT NULL, comment char(64) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL default '', originator int(10) NOT NULL, time_zone char(64) CHARACTER SET latin1 NOT NULL DEFAULT 'SYSTEM', character_set_client char(32) collate utf8_bin, collation_connection char(32) collate utf8_bin, db_collation char(32) collate utf8_bin, body_utf8 longblob, PRIMARY KEY (db, name) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT 'Events'; diff --git a/scripts/mysqld_safe.sh b/scripts/mysqld_safe.sh index 597bf38a518..e6f7ff7b3cb 100644 --- a/scripts/mysqld_safe.sh +++ b/scripts/mysqld_safe.sh @@ -14,12 +14,17 @@ KILL_MYSQLD=1; MYSQLD= niceness=0 -# Default on, unless --log-error is specified (and before options are parsed) -syslog=2 +# Initial logging status: error log is not open, and not using syslog +logging=init +want_syslog=0 +syslog_tag= user=@MYSQLD_USER@ pid_file= err_log= +syslog_tag_mysqld=mysqld +syslog_tag_mysqld_safe=mysqld_safe + trap '' 1 2 3 15 # we shouldn't let anyone kill us umask 007 @@ -46,7 +51,8 @@ Usage: $0 [OPTIONS] --nice=NICE Set the scheduling priority of mysqld --skip-kill-mysqld Don't try to kill stray mysqld processes --syslog Log messages to syslog with 'logger' - --skip-syslog Log messages to error log + --skip-syslog Log messages to error log (default) + --syslog-tag=TAG Pass -t "mysqld-TAG" to 'logger' All other options are passed to the mysqld program. @@ -54,18 +60,46 @@ EOF exit 1 } +my_which () +{ + save_ifs="${IFS-UNSET}" + IFS=: + for file + do + for dir in $PATH + do + if [ -f "$dir/$file" ] + then + echo "$dir/$file" + continue 2 + fi + done + return 1 # Failure, didn't find file in path + done + if [ "$save_ifs" = UNSET ] + then + unset IFS + else + IFS="$save_ifs" + fi + return 0 # Success +} + log_generic () { priority="$1" shift msg="`date +'%y%m%d %H:%M:%S'` mysqld_safe $*" echo "$msg" - if [ $syslog -eq 0 ] - then - echo "$msg" >> "$err_log" - else - logger -i -t mysqld_safe -p "$priority" "$*" - fi + case $logging in + init) ;; # Just echo the message, don't save it anywhere + file) echo "$msg" >> "$err_log" ;; + syslog) logger -t "$syslog_tag_mysqld_safe" -p "$priority" "$*" ;; + *) + echo "Internal program error (non-fatal):" \ + " unknown logging method '$logging'" >&2 + ;; + esac } log_error () { @@ -78,15 +112,23 @@ log_notice () { eval_log_error () { cmd="$1" - if [ $syslog -eq 0 ] - then - cmd="$cmd >> "`shell_quote_string "$err_log"`" 2>&1" - else - # mysqld often (not always) prefixes messages on stdout with a - # timestamp in the form of '%y%m%d %H:%M:%S '; this is redundant - # when logging via syslog, so strip it - cmd="$cmd 2>&1 | sed -e 's/^[0-9]\{6\} [0-9:]\{8\} *//' | logger -i -t mysqld -p daemon.error" - fi + case $logging in + file) cmd="$cmd >> "`shell_quote_string "$err_log"`" 2>&1" ;; + syslog) + # mysqld often prefixes its messages with a timestamp, which is + # redundant when logging to syslog (which adds its own timestamp) + # However, we don't strip the timestamp with sed here, because + # sed buffers output (only GNU sed supports a -u (unbuffered) option) + # which means that messages may not get sent to syslog until the + # mysqld process quits. + cmd="$cmd 2>&1 | logger -t '$syslog_tag_mysqld' -p daemon.error" + ;; + *) + echo "Internal program error (non-fatal):" \ + " unknown logging method '$logging'" >&2 + ;; + esac + #echo "Running mysqld: [$cmd]" eval "$cmd" } @@ -138,8 +180,9 @@ parse_arguments() { --nice=*) niceness="$val" ;; --open-files-limit=*) open_files="$val" ;; --skip-kill-mysqld*) KILL_MYSQLD=0 ;; - --syslog) syslog=1 ;; - --skip-syslog) syslog=0 ;; + --syslog) want_syslog=1 ;; + --skip-syslog) want_syslog=0 ;; + --syslog-tag=*) syslog_tag="$val" ;; --timezone=*) TZ="$val"; export TZ; ;; --help) usage ;; @@ -252,7 +295,19 @@ parse_arguments `$print_defaults $defaults --loose-verbose mysqld_safe safe_mysq parse_arguments PICK-ARGS-FROM-ARGV "$@" # Determine what logging facility to use -if [ -n "$err_log" -o $syslog -eq 0 ] + +# Ensure that 'logger' exists, if it's requested +if [ $want_syslog -eq 1 ] +then + my_which logger > /dev/null 2>&1 + if [ $? -ne 0 ] + then + log_error "--syslog requested, but no 'logger' program found. Please ensure that 'logger' is in your PATH, or do not specify the --syslog option to mysqld_safe." + exit 1 + fi +fi + +if [ -n "$err_log" -o $want_syslog -eq 0 ] then if [ -n "$err_log" ] then @@ -279,14 +334,25 @@ then append_arg_to_args "--log-error=$err_log" - if [ $syslog -eq 1 ] + if [ $want_syslog -eq 1 ] then # User explicitly asked for syslog, so warn that it isn't used - log_error "Can't log to error log and syslog at the same time. Remove all --log-error configuration options for --syslog to take effect. Logging to '$err_log'." + log_error "Can't log to error log and syslog at the same time. Remove all --log-error configuration options for --syslog to take effect." fi - # Don't use syslog since syslog and error log don't mix well - syslog=0 + # Log to err_log file + log_notice "Logging to '$err_log'." + logging=file +else + if [ -n "$syslog_tag" ] + then + # Sanitize the syslog tag + syslog_tag=`echo "$syslog_tag" | sed -e 's/[^a-zA-Z0-9_-]/_/g'` + syslog_tag_mysqld_safe="${syslog_tag_mysqld_safe}-$syslog_tag" + syslog_tag_mysqld="${syslog_tag_mysqld}-$syslog_tag" + fi + log_notice "Logging to syslog." + logging=syslog fi USER_OPTION="" |