mysql check table脚本
2016-07-19 19:08
633 查看
#! /bin/bash
host_name=localhost
#user_name=root
#user_pass=123456
database=mysql
tables=$(mysql --login-path=root -h$host_name $database -A -Bse "show tables")
for table in $tables
do
check_full_status=$(mysql --login-path=root -h$host_name $database -A -Bse "check table $table")
check_status=`echo $check_full_status | awk {'print $4'} | sed s/[[:space:]]//g`
if [ "$check_status" != "OK" ]
then
echo $check_full_status
fi
done
注:mysql --login-path=root这个登录方式是使用了mysql_config_editor set工具
PS1:
执行
mysql -h 主机 -u 用户 -p密码 -P端口 -D库 -Bse “select house_id,type from 表名 where account_id=123;” > /tmp/a.txt
PS2:
MySQL在切换库时报使用-A参数
在使用user dbname 时会出现速度慢的现象,并报提示:
mysql> use dbname
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
然后就卡在这里。
原因是当我们打开数据库,即use dbname时,要预读数据库信息。由于数据库太大,即数据库中表非常多,所以如果预读数据库信息,将非常慢,所以就卡住了,如果数据库中表非常少,将不会出现问题。
解决办法mysql已经有所提示:
我们进入mysql 时,没有使用-A参数:
mysql> mysql -hhostname -uusername -ppassword -Pport
当使用-A参数时,就不预读数据库信息,速度就会快起来:
mysql> mysql -hhostname -uusername -ppassword -Pport -A
host_name=localhost
#user_name=root
#user_pass=123456
database=mysql
tables=$(mysql --login-path=root -h$host_name $database -A -Bse "show tables")
for table in $tables
do
check_full_status=$(mysql --login-path=root -h$host_name $database -A -Bse "check table $table")
check_status=`echo $check_full_status | awk {'print $4'} | sed s/[[:space:]]//g`
if [ "$check_status" != "OK" ]
then
echo $check_full_status
fi
done
注:mysql --login-path=root这个登录方式是使用了mysql_config_editor set工具
PS1:
Linux下把MySQL的查询结果保存的文件中去
执行mysql -h 主机 -u 用户 -p密码 -P端口 -D库 -Bse “select house_id,type from 表名 where account_id=123;” > /tmp/a.txt
PS2:
MySQL在切换库时报使用-A参数
在使用user dbname 时会出现速度慢的现象,并报提示:
mysql> use dbname
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
然后就卡在这里。
原因是当我们打开数据库,即use dbname时,要预读数据库信息。由于数据库太大,即数据库中表非常多,所以如果预读数据库信息,将非常慢,所以就卡住了,如果数据库中表非常少,将不会出现问题。
解决办法mysql已经有所提示:
我们进入mysql 时,没有使用-A参数:
mysql> mysql -hhostname -uusername -ppassword -Pport
当使用-A参数时,就不预读数据库信息,速度就会快起来:
mysql> mysql -hhostname -uusername -ppassword -Pport -A
相关文章推荐
- MySQL for Windows 解压缩版配置安装
- **MYSQL** 创建数据表
- MySQL性能优化的最佳20+
- mysql主从复制配置
- mysql 基础操作全覆盖(适用与兼职DBA,不定期更新) 推荐
- MySQL执行SHOW STATUS查询服务器状态状态之Handler_read_* 详解
- mysql case语句的使用
- MYSQL: Handler_read_%参数说明
- 【MySQL】 [1045]Access denied for user ‘root’@’localhost’ 错误解决方法总结
- mysql密码忘了的解决方法
- mysql 性能优化方向
- MySQL Order By实现原理分析和Filesort优化
- mysql悲观锁总结和实践
- Mysql
- MySQL innobackupex在线备份及恢复(全量和增量)
- mysql乐观锁解析
- mysql修改时区
- 【Mysql】安装完成,无法写入配置文件,提示configuration file template XX be processed and written to XX Error code-1
- mysql delete删除记录数据库空间不减少问题解决方法
- mysql 5.6.30 开启慢查询日志