shell 中调用 mysql 操作
#!/bin/bash
#删除100个数据库中的1000个表的过期数据
DBHOST="127.0.0.1"
DBPWD="pwd"
DBUSER="root"
MYSQLBIN="/usr/local/mysql/bin/mysql"
for((dbindex = 0;dbindex < 100;dbindex++))
do
for((tabindex = 0;tabindex < 10;tabindex++))
do
if [ $dbindex -lt 10 ]; then
del="delete from gs_map_0${dbindex}.t_${tabindex}";
else
del="delete from gs_map_${dbindex}.t_${tabindex}";
fi
del=${del}" where Fcreate_time < UNIX_TIMESTAMP() - 86400"
bin=`${MYSQLBIN} -u${DBUSER} -p${DBPWD} -h${DBHOST} -e"${del}"`
$bin
#echo ${bin}
#echo $del >>/tmp/aaa.txt
sleep 5
done
done
#crontab configure
# 0 3 * * * clear.sh > /dev/null 2>&1
相关文档:
/**********************by garcon1986***************************************/
错误代码如下:
#1045 - Access denied for user 'root'@'localhost' (using password: YES)
$cd /etc/mysql
$mysql -u root -p
出现错误#1045
尝试了很多方法后,在网络上找到了解决方法。
$cd /etc/mysql
$gedit debian.cnf
找到 ......
一.安装
rpm方式
rpm -ivf MySQL*
tar方式
tar xzvf mysql-x.xx.tar.gz
cd mysqlp-x.xx 生成makefile
./congigure
make 编译
make install
mysql_install_db
二.启动、关闭
ser ......
先下载一个mysql的驱动器:(我下的是mysql-connector-java-3.1.11-bin.jar)
将它放到java\lib目录下
在环境变量的CLASSPATH里添加该类(%JAV_HOMG%\lib\mysql-connector-java-3.1.11-bin.jar)
出测试该段代码即可:
import java.net.URL;
import java.sql.*;
public class sqlTest {
public static void mai ......
(1)INFORMATION_SCHEMA
select (sum(data_length) + sum(index_length))/(1024*1024) from INFORMATION_SCHEMA.`TABLES` where table_schema = 'your_table_schema' and table_name like 'your_table_name';
(2)show table status like '';
try {
Class.forName("com.mysql.jdbc.Driver");
......
1.建表过程如下
create database test default character set utf8 collate utf8_general_ci
use test;
create table devicedata
(
ID int auto_increment PRIMARY key ,
TimeStamp datetime,
Device_Name varchar(100),
Tag_Name varchar(100),
Value varchar(50)
)
2 ......