MySQL基本操作(三):全文本搜索
2015-08-31 09:38
966 查看
1、MyISAM支持全文本搜索,而InnoDB不支持。因此要在创建表的时候,加上engine=MyISAM;
2、一般在创建表时启用全文本搜索。在定义之后,MySQL自动维护该索引。在增加、更新或删除行时,索引随之自动更新。
3、不要在导入数据时使用FULLTEXT
4、建表并导入数据
(1)建表如图
![](https://img-blog.csdn.net/20150831093552140)
(2)导入数据如图
![](https://img-blog.csdn.net/20150831093621648)
(3)代码如下
6、进行全文本搜索
进行全文本搜索,必须索引被搜索的列,而且要随着数据的改变不断地重新索引。在对表列进行适当设计后,MySQL会自动进行所有的索引和重新索引。
在索引之后,SELECT可与Match()和Against()一起使用以实际执行搜索。
(1)布尔文本搜索(boolean mode)
/* 匹配designed*/
![](https://img-blog.csdn.net/20150831093320728)
/* 匹配This或匹配systems */
![](https://img-blog.csdn.net/20150831093134171)
或者
![](https://img-blog.csdn.net/20150831093202638)
其他搜索方法有待完善。
2、一般在创建表时启用全文本搜索。在定义之后,MySQL自动维护该索引。在增加、更新或删除行时,索引随之自动更新。
3、不要在导入数据时使用FULLTEXT
4、建表并导入数据
(1)建表如图
(2)导入数据如图
(3)代码如下
#!/usr/bin/python # encoding: utf-8 import MySQLdb # 打开数据库连接 conn = MySQLdb.connect(host="localhost", user="root", passwd="111111", db="ltz") # 使用cursor()方法获取操作游标 cursor = conn.cursor() # 如果数据表已经存在使用 execute() 方法删除表。 cursor.execute("DROP TABLE IF EXISTS productnotes") #1. 创建数据表SQL语句 sql = """CREATE TABLE productnotes( note_id int not null auto_increment, note_text text null, primary key(note_id), fulltext(note_text))engine=MyISAM;""" #使用fulltext()&&engine=MyISAM! cursor.execute(sql) #2. SQL 一次插入多条记录!!!!!!! sql = """INSERT INTO productnotes( note_id, note_text) VALUES ('1', "LimsLink is designed to interface output from chromatography data systems (CDSs) to LIMS."), ('2', "This line of proprietary reagents, containers, and automation tools is designed for genomics and drug discovery research."), ('3', "line reagents, containers, tools is designed for genomics and drug discovery research."), ('4', "specificities include both alpha–beta and beta–beta. This line from chromatography .data systems (CDSs) and toLIMS.");""" try: # 执行sql语句 cursor.execute(sql) # 提交到数据库执行 conn.commit() except: # Rollback in case there is any error conn.rollback() conn.close()
6、进行全文本搜索
进行全文本搜索,必须索引被搜索的列,而且要随着数据的改变不断地重新索引。在对表列进行适当设计后,MySQL会自动进行所有的索引和重新索引。
在索引之后,SELECT可与Match()和Against()一起使用以实际执行搜索。
(1)布尔文本搜索(boolean mode)
/* 匹配designed*/
/* 匹配This或匹配systems */
或者
其他搜索方法有待完善。
相关文章推荐
- PHP8新特性之match表达式
- MySQL中的integer 数据类型
- MySQL存储过程
- mysql中int、bigint、smallint 和 tinyint的区别与长度
- mysql load data 导出、导入 csv
- source命令执行SQL脚本文件
- MySQL创建用户及权限控制
- MySQL管理数据表
- linux下mysql添加用户
- mysql procedure
- mysql触发器
- MySQL 备份和恢复策略
- mac下安装mysql(转载)
- mysql 修改编码 Linux/Mac/Unix/通用(杜绝修改后无法启动的情况!)
- MySQL数据的导出、导入(mysql内部命令:mysqldump、mysql)
- mysql数据行转列
- Linux下修改MySQL编码的方法
- MySQL Server 日志
- MySQL 安全事宜