not in 效率太低
所以用left join来处理
SELECT id FROM `fa_user` AS A LEFT JOIN
(SELECT user_id as i FROM `fa_third`) AS B ON A.id=B.i
WHERE B.i IS NULL
not in 效率太低
所以用left join来处理
SELECT id FROM `fa_user` AS A LEFT JOIN
(SELECT user_id as i FROM `fa_third`) AS B ON A.id=B.i
WHERE B.i IS NULL
早上到公司同时说数据库的表丢了,上去一看确实丢了,由于断过一次电,怀疑断电导致的,但是一想想断电出现的问题就不止只丢失一个表的事啊,先看一下日志和同时反馈的问题。
同时直接给我发了这样的一条消息:
Table './we7_71yunduan_to/ims_mc_members' is marked as crashed and should be repaired
那就检查一下这个表具体的问题!
mysql> use we7_71yunduan_to
Database changed
mysql> check table ims_mc_members
-> ;
+---------------------------------+-------+----------+----------------------------------------------------------------+
| Table | Op | Msg_type | Msg_text |
+---------------------------------+-------+----------+----------------------------------------------------------------+
| we7_71yunduan_to.ims_mc_members | check | warning | Table is marked as crashed |
| we7_71yunduan_to.ims_mc_members | check | warning | 1 client is using or hasn't closed the table properly |
| we7_71yunduan_to.ims_mc_members | check | error | Found key at page 26624 that points to record outside datafile |
| we7_71yunduan_to.ims_mc_members | check | error | Corrupt |
+---------------------------------+-------+----------+----------------------------------------------------------------+
4 rows in set (0.04 sec)
mysql> repair table ims_mc_members
-> ;
+---------------------------------+--------+----------+----------------------------------------------+
| Table | Op | Msg_type | Msg_text |
+---------------------------------+--------+----------+----------------------------------------------+
| we7_71yunduan_to.ims_mc_members | repair | info | Wrong bytesec: 0- 0- 0 at 70372; Skipped |
| we7_71yunduan_to.ims_mc_members | repair | warning | Number of rows changed from 243 to 242 |
| we7_71yunduan_to.ims_mc_members | repair | status | OK |
+---------------------------------+--------+----------+----------------------------------------------+
3 rows in set (0.11 sec)
mysql> check table ims_mc_members;
+---------------------------------+-------+----------+----------+
| Table | Op | Msg_type | Msg_text |
+---------------------------------+-------+----------+----------+
| we7_71yunduan_to.ims_mc_members | check | status | OK |
+---------------------------------+-------+----------+----------+
1 row in set (0.00 sec)
mysql>
在处理过程发现表有两个警告和两个错误:表崩了,表被占着或关的姿势不对。。。。
处理方法就是repair table ims_mc_members
最后再检查一下问题结局
1、检查并修改mysql的my.ini的配置文件
default-character-set=utf8
2、建立数据库是要指定字符集
create database mydb default character set utf8 collate utf8_general_ci;
3、建立数据表示也要指定字符集:
出问题的命令:
CREATE TABLE IF NOT EXISTS `mydb` (
`id` varchar(64) NOT NULL,
`name` int(11) NOT NULL,
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
正确的命令:
CREATE TABLE IF NOT EXISTS `mydb` (
`id` varchar(64) NOT NULL,
`name` int(11) NOT NULL,
) ENGINE=InnoDB DEFAULT CHARSET=utf8;