📄 mysql_setpermission
字号:
} } } else { print "Type either database name or * meaning any databasename. That means"; print " any of those above but also any which will be created in future!"; print " This option gives a user chance to operate on databse mysql, which"; print " contains privilege settings. That is really risky!\n"; next; } if ($good == 1) { last; } else { print "You must select one from the list.\nTry again: "; next; } } print "The database $db will be used.\n"; return($db);}#### ask for a new username###sub newuser{ my $user = ""; my $answer = ""; print "\nWhat username is to be created: "; while(<STDIN>) { $answer = $_; chomp($answer); if ($answer) { $user = $answer; } else { print "You must type something ...\nTry again: "; next; } last; } print "Username = $user\n"; return($user);}#### ask for a user which is already in the user table###sub user{ my ($answer,$user); print "\nFor which user do you want to specify a password: "; while(<STDIN>) { $answer = $_; chomp($answer); if ($answer) { my $sth = $dbh->prepare("select User from user where User = '$answer'") || die $dbh->errstr; $sth->execute || die $dbh->errstr; my @r = $sth->fetchrow_array; if ($r[0]) { $user = $r[0]; } else { print "Sorry, user $answer isn't known in the user table.\nTry again: "; next; } } else { print "You must type something ...\nTry again: "; next; } last; } print "Username = $user\n"; return($user);}#### ask for a new password###sub newpass{ my ($user) = @_; my ($pass,$answer,$good,$yes); print "Would you like to set a password for $user [y/n]: "; $yes = <STDIN>; chomp($yes); if ($yes =~ /y/) { system "stty -echo"; print "What password do you want to specify for $user: "; while(<STDIN>) { $answer = $_; chomp($answer); system "stty echo"; print "\n"; if ($answer) { system "stty -echo"; print "Type the password again: "; my $second = <STDIN>; chomp($second); system "stty echo"; print "\n"; if ($answer ne $second) { print "Passwords aren't the same; we begin from scratch again.\n"; system "stty -echo"; print "Password please: "; next; } else { $pass = $answer; } } else { print "You must type something ...\nTry again: "; next; } last; }# print "The password for $user is $pass.\n"; } else { print "We won't set a password so the user doesn't have to use it\n"; $pass = ""; } return($pass);}#### ask for new hosts###sub newhosts{ my ($host,$answer,$good); print "We now need to know from what host(s) the user will connect.\n"; print "Keep in mind that % means 'from any host' ...\n"; print "The host please: "; while(<STDIN>) { $answer = $_; chomp($answer); if ($answer) { $host .= ",$answer"; print "Would you like to add another host [yes/no]: "; my $yes = <STDIN>; chomp($yes); if ($yes =~ /y/i) { print "Okay, give us the host please: "; next; } else { print "Okay we keep it with this ...\n"; } } else { print "You must type something ...\nTry again: "; next; } last; } $host =~ s/^,//; print "The following host(s) will be used: $host.\n"; return($host);}#### ask for a host which is already in the user table###sub hosts{ my ($user) = @_; my ($answer,$good,$host); print "We now need to know which host for $user we have to change.\n"; print "Choose from the following hosts: \n"; $user = $dbh->quote($user); my $sth = $dbh->prepare("select Host,User from user where User = $user") || die $dbh->errstr; $sth->execute || die $dbh->errstr; while (my @r = $sth->fetchrow_array) { print " - $r[0] \n"; } print "The host please (case sensitive): "; while(<STDIN>) { $answer = $_; chomp($answer); if ($answer) { $sth = $dbh->prepare("select Host,User from user where Host = '$answer' and User = $user") || die $dbh->errstr; $sth->execute || die $dbh->errstr; my @r = $sth->fetchrow_array; if ($r[0]) { $host = $answer; last; } else { print "You have to select a host from the list ...\nTry again: "; next; } } else { print "You have to type something ...\nTry again: "; next; } last; } print "The following host will be used: $host.\n"; return($host);}#### a nice quit (first disconnect and then exit###sub quit{ $dbh->disconnect; exit(0);}#### Read variables password, port and socket from .my.cnf under the client# or perl groups###sub read_my_cnf{ open(TMP,$ENV{'HOME'} . "/.my.cnf") || return 1; while (<TMP>) { if (/^\[(client|perl)\]/i) { while ((defined($_=<TMP>)) && !/^\[\w+\]/) { print $_; if (/^host\s*=\s*(\S+)/i) { $opt_host = $1; } elsif (/^user\s*=\s*(\S+)/i) { $opt_user = $1; } elsif (/^password\s*=\s*(\S+)/i) { $opt_password = $1; } elsif (/^port\s*=\s*(\S+)/i) { $opt_port = $1; } elsif (/^socket\s*=\s*(\S+)/i) { $opt_socket = $1; } } } } close(TMP);}#### the help text###sub usage{ print <<EOL;---------------------------------------------------------------------- The permission setter for MySQL. version: $version made by: Luuk de Boer <luuk\@wxs.nl>----------------------------------------------------------------------The permission setter is a little program which can help you add usersor databases or change passwords in MySQL. Keep in mind that we don'tcheck permissions which already been set in MySQL. So if you can'tconnect to MySQL using the permission you just added, take a look atthe permissions which have already been set in MySQL.The permission setter first reads your .my.cnf file in your Homedirectory if it exists.Options for the permission setter:--help : print this help message and exit.The options shown below are used for making the connection to the MySQLserver. Keep in mind that the permissions for the user specified viathese options must be sufficient to add users / create databases / setpasswords.--user : is the username to connect with.--password : the password of the username.--host : the host to connect to.--socket : the socket to connect to.--port : the port number of the host to connect to.If you don't give a password and no password is set in your .my.cnffile, then the permission setter will ask for a password.EOLexit(0);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -