Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
centos
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
CI / CD Analytics
Repository Analytics
Value Stream Analytics
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
platyhouse
centos
Commits
547d5592
Commit
547d5592
authored
Dec 03, 2019
by
root
1
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added pty_mysql_optimize.sh
parent
4b82a725
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
96 additions
and
0 deletions
+96
-0
pty_mysql_optimize.sh
pty_mysql_optimize.sh
+96
-0
No files found.
pty_mysql_optimize.sh
0 → 100755
View file @
547d5592
#!/usr/bin/php
<?php
$password
=
$argv
[
1]
;
$host
=
$argv
[
2]
;
$user
=
$argv
[
3]
;
if
(!
$password
)
{
echo
"pty_mysql_optimize.sh version 1.0
\n
"
;
echo
"Copyright (C) 2019 by cpueblo, PlatyHouse Co.,LTD.
\n
"
;
echo
"Web site: https://www.platyhouse.com/
\n\n
"
;
echo
"Usage ./pty_mysql_optimize.sh <MYSQL ROOT PASSWORD> <HOST (default: localhost)> <USERNAME (default: root)>
\n
"
;
exit
;
}
if
(!
$host
)
$host
=
"localhost"
;
if
(!
$user
)
$user
=
"root"
;
$connection
=
mysqli_connect
(
$host
,
$user
,
$password
)
;
if
(!
$connection
)
{
die
(
'Could not connect database.'
.
mysqli_error
()
.
"
\n
"
)
;
}
$databases
=
mysqli_query
(
$connection
,
"SHOW databases"
)
;
while
(
$databaseInfo
=
mysqli_fetch_array
(
$databases
))
{
// go through each row that was returned
in
$result
$dbName
=
$databaseInfo
[
0]
;
if
(
$dbName
==
"performance_schema"
)
continue
;
if
(
$dbName
==
"mysql"
)
continue
;
if
(
$dbName
==
"sys"
)
continue
;
if
(
$dbName
==
"information_schema"
)
continue
;
echo
"====================================
\n
database =
$dbName
\n
====================================
\n
"
;
mysql_innodb_defragment
(
$host
,
$user
,
$password
,
$dbName
)
;
}
echo
"finished
\n
"
;
mysqli_close
(
$connection
)
;
function
mysql_innodb_defragment
(
$host
,
$user
,
$password
,
$dbName
)
{
$connection
=
mysqli_connect
(
$host
,
$user
,
$password
)
;
if
(!
$connection
)
{
die
(
'Could not connect:'
.
mysql_error
())
;
}
mysqli_select_db
(
$connection
,
$dbName
)
;
$showtables
=
mysqli_query
(
$connection
,
"SHOW TABLES FROM
`
{
$dbName
}
`
"
)
;
while
(
$tableInfo
=
mysqli_fetch_array
(
$showtables
))
{
// go through each row that was returned
in
$result
$tableName
=
$tableInfo
[
0]
;
echo
(
"table = {
$tableName
}
\n
"
)
;
// print the table that was returned on that row.
$n
=
mysqli_query
(
$connection
,
"SHOW TABLE STATUS FROM
`
{
$dbName
}
`
WHERE
`
Name
`
= '{
$tableName
}'"
)
;
$tableStatus
=
mysqli_fetch_array
(
$n
)
;
echo
"checking table.
\n
"
;
mysqli_query
(
$connection
,
"CHECK TABLE
`
{
$tableName
}
`
"
)
;
if
(
$tableStatus
[
'Engine'
]
==
"InnoDB"
)
{
echo
"alter table.
\n
"
;
mysqli_query
(
$connection
,
"ALTER TABLE
`
{
$tableName
}
`
ENGINE=InnoDB"
)
;
}
else
{
echo
"alter table passed. engine = {
$tableStatus
['Engine']}
\n
"
;
}
echo
"analyze table.
\n
"
;
mysqli_query
(
$connection
,
"ANALYZE TABLE
`
{
$tableName
}
`
"
)
;
echo
"optimize table.
\n
"
;
mysqli_query
(
$connection
,
"OPTIMIZE TABLE
`
{
$tableName
}
`
"
)
;
echo
"flush table.
\n
"
;
mysqli_query
(
$connection
,
"FLUSH TABLE
`
{
$tableName
}
`
"
)
;
echo
"
\n
"
;
}
mysqli_close
(
$connection
)
;
}
?>
platyhouse
@platyhouse
mentioned in commit
8587004b
·
Dec 16, 2025
mentioned in commit
8587004b
mentioned in commit 8587004bfbebb2ceff13804bc1eea04727f6a285
Toggle commit list
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment