Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
ensembl
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Iterations
Wiki
Requirements
Jira
Code
Merge requests
1
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ensembl-gh-mirror
ensembl
Commits
473c7216
Commit
473c7216
authored
13 years ago
by
Monika Komorowska
Browse files
Options
Downloads
Patches
Plain Diff
Script for killing mysql processes by db name pattern.
parent
0fe07321
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
misc-scripts/db/kill_process_by_db.pl
+81
-0
81 additions, 0 deletions
misc-scripts/db/kill_process_by_db.pl
with
81 additions
and
0 deletions
misc-scripts/db/kill_process_by_db.pl
0 → 100644
+
81
−
0
View file @
473c7216
# kill processes by db pattern
# Author: Monika Komorowska
# Date : May 2011
use
strict
;
use
DBI
;
use
Getopt::
Long
;
my
(
$host
,
$user
,
$pass
,
$port
,
$dbpattern
);
GetOptions
(
"
host|h=s
",
\
$host
,
"
user|u=s
",
\
$user
,
"
pass|p=s
",
\
$pass
,
"
port|P=i
",
\
$port
,
"
dbpattern|pattern=s
",
\
$dbpattern
,
);
if
(
!
$host
||
!
$user
||
!
$pass
||
!
$dbpattern
)
{
usage
();
}
my
$dsn
=
"
DBI:mysql:host=
$host
";
if
(
$port
)
{
$dsn
.=
"
;port=
$port
";
}
my
$db
=
DBI
->
connect
(
$dsn
,
$user
,
$pass
);
my
$sth
=
$db
->
prepare
("
SHOW FULL PROCESSLIST
")
||
die
$
DBI::
err
.
"
:
"
.
$
DBI::
errstr
;
$sth
->
execute
||
die
DBI::
err
.
"
:
"
.
$
DBI::
errstr
;
my
$ref
;
print
"
Id
\t
User
\t
Host
\t
db
\t
Command
\t
Time
\t
State
\t
Info
\n
";
my
@proc_ids
;
while
(
$ref
=
$sth
->
fetchrow_hashref
()
)
{
if
(
$$ref
{'
db
'}
=~
/$dbpattern/
)
{
push
(
@proc_ids
,
$$ref
{'
Id
'});
print
"
$
$ref
{'Id'}
\t
$
$ref
{'Host'}
\t
$
$ref
{'db'}
\t
$
$ref
{'Command'}
\t
$
$ref
{'Time'}
\t
$
$ref
{'State'}
\t
$
$ref
{'Info'}
\n
";
}
}
my
$proc_id_count
=
@proc_ids
;
if
(
$proc_id_count
>
0
)
{
print
"
Are you sure you want to kill process(es) listed above? (y/n)
\n
";
}
else
{
print
"
No processes found for db pattern
$dbpattern
\n
";
}
my
$decision
=
<>
;
if
(
$decision
==
'
y
')
{
my
$killed_count
=
0
;
foreach
my
$proc_id
(
@proc_ids
)
{
if
(
$db
->
do
("
KILL
$proc_id
")
)
{
$killed_count
++
;
}
else
{
print
$
DBI::
errstr
;
}
}
print
"
$killed_count
procesess were killed
\n
";
}
sub
usage
{
print
STDERR
<<EOF
Usage: kill_process_by_db options
Where options are: -host hostname
-user username
-pass password
-port port_of_server optional
-dbpattern regular expression that the database name has to match
EOF
;
exit
;
}
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment