Thank you for reading...
2008/11/16 22:05
2008/11/05 13:36
稍微解释下:
先把要唯一的字段(我这里是licenseID)用group把多于1个的数据找出来做为b表,同时把最小的ID选中,然后于原表a表关联,把大于最小ID的数据删除。
delete hxtable as a from hxtable a,
(
select licenseID,min(id) as id from hxtable group by licenseID having count(*) > 1
) as b
where a.licenseID = b.licenseID and a.id > b.id
同理,如果要保留最新的ID,可以这样写:
delete hxtable as a from hxtable a,
(
select licenseID,max(id) as id from hxtable group by licenseID having count(*) > 1
) as b
where a.licenseID = b.licenseID and a.id < b.id
先把要唯一的字段(我这里是licenseID)用group把多于1个的数据找出来做为b表,同时把最小的ID选中,然后于原表a表关联,把大于最小ID的数据删除。
delete hxtable as a from hxtable a,
(
select licenseID,min(id) as id from hxtable group by licenseID having count(*) > 1
) as b
where a.licenseID = b.licenseID and a.id > b.id
同理,如果要保留最新的ID,可以这样写:
delete hxtable as a from hxtable a,
(
select licenseID,max(id) as id from hxtable group by licenseID having count(*) > 1
) as b
where a.licenseID = b.licenseID and a.id < b.id
2008/09/20 19:27
换了块硬盘,重装了MYSQL。装好后,停掉MYSQL服务,把原MYSQL的data目录copy了过来。启动时发现启动不起来了
去事件日志查看,出现了两条错误信息:
第一条显示:
Default storage engine (InnoDB) is not available
For more information, see Help and Support Center at http://www.mysql.com.
第二条显示:
Aborting
For more information, see Help and Support Center at http://www.mysql.com.
在SE搜索“Default storage engine (InnoDB) is not available”找到这篇文章,
http://blog.csdn.net/woowindice/archive/2007/04/10/1559206.aspx
根据说明,将文中所提到的ib_logfile0,ib_logfile1,还有ibdata1都删除,这三个目录都在data目录下。
再次启动MYSQL服务,成功!
在DOS状态下进入MYSQL,show databases一下,所有数据库都出来了,问题解决:)
去事件日志查看,出现了两条错误信息:
第一条显示:
Default storage engine (InnoDB) is not available
For more information, see Help and Support Center at http://www.mysql.com.
第二条显示:
Aborting
For more information, see Help and Support Center at http://www.mysql.com.
在SE搜索“Default storage engine (InnoDB) is not available”找到这篇文章,
http://blog.csdn.net/woowindice/archive/2007/04/10/1559206.aspx
根据说明,将文中所提到的ib_logfile0,ib_logfile1,还有ibdata1都删除,这三个目录都在data目录下。
再次启动MYSQL服务,成功!
在DOS状态下进入MYSQL,show databases一下,所有数据库都出来了,问题解决:)
2008/08/14 22:30
因为一些原因,对数据库进行了迁移,可能是在操作时由于使用了kill来结束mysqld,导致了一些数据损坏。
迁到新数据库后,以下是是些错误信息。
Warning: mysql_query(): Unable to save result set in /www/hx/include/db_mysql.class.php on line 58
SQL: select count(0) from hx_subject where isdel=0 and classid=9
Error: Got error 134 from storage engine
Errno.: 1030
最后,用myisamchk和optimize table tablename等方法,全部修复完成。
一般优化表后的提示是OK,如下表:
mysql> OPTIMIZE TABLE `hx_focus`;
+----------------+----------+----------+----------+
| Table | Op | Msg_type | Msg_text |
+----------------+----------+----------+----------+
| dashi.hx_focus | optimize | status | OK |
+----------------+----------+----------+----------+
但这个表发现提示:Table is already up to date 。
mysql> OPTIMIZE TABLE `hx_key`;
+--------------+----------+----------+-----------------------------+
| Table | Op | Msg_type | Msg_text |
+--------------+----------+----------+-----------------------------+
| dashi.hx_key | optimize | status | Table is already up to date |
+--------------+----------+----------+-----------------------------+
查了下:Table is already up to date means that the storage engine for the table indicated that there was no need to check the table.
原来是不需要检查,挺好:)
另外,关闭数据库最好不要用kill,很容易造成数据损坏。建议使用:
bin/mysqladmin -u root shutdown
或
/usr/local/mysql/support-files/mysql.server stop
----------------------------------------------------------------------------------------
web在厦门,mysql数据库在北京后,这几天经常出现连接数据库 Too many connections。
经分析,怀疑是远程连接容易造成Too many connections。
用show processlist查看,发现大量的unauthenticated user,可能占了99%。。。
查了一下,解决办法有二:
1、启动时带参数 --skip-name-resolve
2、访问的主机授权时用IP,最好把该主机的IP及主机名写到/etc/hosts文件中
可参阅:http://www.itlearner.com/article/2008/4184.shtml
原启动方式:
/usr/local/mysql/bin/mysqld_safe --max_connections=500 --max_connect_errors=50000 --user=mysql --maximum-wait-timeout=100 --maximum-interactive_timeout=100 &
更新后启动方式:
/usr/local/mysql/bin/mysqld_safe --max_connections=500 --max_connect_errors=50000 --user=mysql --maximum-wait-timeout=100 --maximum-interactive_timeout=100 --skip-name-resolve &
重启后问题解决:)
---------------------------------------------------------------------------------------
删除一个用户的权限
revoke all on *.* from hxtest@localhost;
delete from mysql.user where user='hxtest' and host='localhost';
可以用show grants for hxtest,来查看hxtest已有的权限。
迁到新数据库后,以下是是些错误信息。
Warning: mysql_query(): Unable to save result set in /www/hx/include/db_mysql.class.php on line 58
SQL: select count(0) from hx_subject where isdel=0 and classid=9
Error: Got error 134 from storage engine
Errno.: 1030
最后,用myisamchk和optimize table tablename等方法,全部修复完成。
一般优化表后的提示是OK,如下表:
mysql> OPTIMIZE TABLE `hx_focus`;
+----------------+----------+----------+----------+
| Table | Op | Msg_type | Msg_text |
+----------------+----------+----------+----------+
| dashi.hx_focus | optimize | status | OK |
+----------------+----------+----------+----------+
但这个表发现提示:Table is already up to date 。
mysql> OPTIMIZE TABLE `hx_key`;
+--------------+----------+----------+-----------------------------+
| Table | Op | Msg_type | Msg_text |
+--------------+----------+----------+-----------------------------+
| dashi.hx_key | optimize | status | Table is already up to date |
+--------------+----------+----------+-----------------------------+
查了下:Table is already up to date means that the storage engine for the table indicated that there was no need to check the table.
原来是不需要检查,挺好:)
另外,关闭数据库最好不要用kill,很容易造成数据损坏。建议使用:
bin/mysqladmin -u root shutdown
或
/usr/local/mysql/support-files/mysql.server stop
----------------------------------------------------------------------------------------
web在厦门,mysql数据库在北京后,这几天经常出现连接数据库 Too many connections。
经分析,怀疑是远程连接容易造成Too many connections。
用show processlist查看,发现大量的unauthenticated user,可能占了99%。。。
查了一下,解决办法有二:
1、启动时带参数 --skip-name-resolve
2、访问的主机授权时用IP,最好把该主机的IP及主机名写到/etc/hosts文件中
可参阅:http://www.itlearner.com/article/2008/4184.shtml
原启动方式:
/usr/local/mysql/bin/mysqld_safe --max_connections=500 --max_connect_errors=50000 --user=mysql --maximum-wait-timeout=100 --maximum-interactive_timeout=100 &
更新后启动方式:
/usr/local/mysql/bin/mysqld_safe --max_connections=500 --max_connect_errors=50000 --user=mysql --maximum-wait-timeout=100 --maximum-interactive_timeout=100 --skip-name-resolve &
重启后问题解决:)
---------------------------------------------------------------------------------------
删除一个用户的权限
revoke all on *.* from hxtest@localhost;
delete from mysql.user where user='hxtest' and host='localhost';
可以用show grants for hxtest,来查看hxtest已有的权限。
2008/01/24 10:56
一个Discuz论坛,原来架在windows下,用的是GBK编码,MYSQL版本是5.0的。
现在需要转移到Linux下,我本来建议用mysqldump导出的方法,但同事希望直接用data目录下的数据库目录。
那就先用移目录的方式试下,在新服务器创建数据库,然后将旧的目录移过来。
在mysql中,Select之类的都正常,但在网页程序中提示:Table 'cdb_posts' is read only
给数据库目录的所属用户和组改为mysql,并加上777的权限,还是一样提示。
程序中使用root连接,也是一样的提示。
想用myisamchk来检查一下,也提示read only。
最终在这里找到了解决方法:http://www.mysqltalk.org/re-the-table-is-read-only-vt154092.html
运行flush-tables后,read only问题解决:)
然后发现数据结构和内容还是有问题,用myisamchk查错无效,后来用mysqldump导,不过也还是碰到了一大堆问题,由于要转的数据库挺大,化了很长时间,最终没有继续下去。
了解了一些知识点,记录一下:
就是mysql5导出的有default-charact的设置,mysql4不支持,需要加skip-opt参数,如:
mysqldump -uroot -p --default-character-set=gbk -skip-opt databse > hx.sql
参考文章:Mysql 数据库字符集转换
最后找了台mysql5的服务器,用mysqldump导出,mysql导入,一次成功!
发现用mysqldump导出一个表,300w多条记录,用了才4分多钟,每秒处理1w多记录,快啊!导入时,差不多用了十几分钟,每秒导入几千条也很快了:)
现在需要转移到Linux下,我本来建议用mysqldump导出的方法,但同事希望直接用data目录下的数据库目录。
那就先用移目录的方式试下,在新服务器创建数据库,然后将旧的目录移过来。
在mysql中,Select之类的都正常,但在网页程序中提示:Table 'cdb_posts' is read only
给数据库目录的所属用户和组改为mysql,并加上777的权限,还是一样提示。
程序中使用root连接,也是一样的提示。
想用myisamchk来检查一下,也提示read only。
最终在这里找到了解决方法:http://www.mysqltalk.org/re-the-table-is-read-only-vt154092.html
引用
I just encountered a similar problem on one of my production servers
this morning. (I'm still investigating the cause.) After doing a
quick bit of Google-searching, this solved my problem:
mysqladmin -u <username> -p flush-tables
By the way: All directories in /var/lib/mysql should have 700
permissions (owned my the mysql user) and everything within those
directories should be 660 (owned by the mysql user and mysql group).
this morning. (I'm still investigating the cause.) After doing a
quick bit of Google-searching, this solved my problem:
mysqladmin -u <username> -p flush-tables
By the way: All directories in /var/lib/mysql should have 700
permissions (owned my the mysql user) and everything within those
directories should be 660 (owned by the mysql user and mysql group).
运行flush-tables后,read only问题解决:)
然后发现数据结构和内容还是有问题,用myisamchk查错无效,后来用mysqldump导,不过也还是碰到了一大堆问题,由于要转的数据库挺大,化了很长时间,最终没有继续下去。
了解了一些知识点,记录一下:
就是mysql5导出的有default-charact的设置,mysql4不支持,需要加skip-opt参数,如:
mysqldump -uroot -p --default-character-set=gbk -skip-opt databse > hx.sql
参考文章:Mysql 数据库字符集转换
最后找了台mysql5的服务器,用mysqldump导出,mysql导入,一次成功!
发现用mysqldump导出一个表,300w多条记录,用了才4分多钟,每秒处理1w多记录,快啊!导入时,差不多用了十几分钟,每秒导入几千条也很快了:)







