前面说了,coreseek sphinx mmseg mysql等的安装,下面说一下怎么使用。 一,coreseek sphinx启动后,会多出一个端口,并且可以像mysql一样登录,但不是登录mysql [root@localhost tank]# mysql -h 127.0.0.1 -P 9306 //不是真的连接mysql,而连接了sphinx in
前面说了,coreseek sphinx mmseg mysql等的安装,下面说一下怎么使用。
一,coreseek sphinx启动后,会多出一个端口,并且可以像mysql一样登录,但不是登录mysql
[root@localhost tank]# mysql -h 127.0.0.1 -P 9306 //不是真的连接mysql,而连接了sphinx index Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 1 Server version: 1.11-id64-dev (r2540) Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> select * from tank_test where match('坦克') ; //这种写法,根原装的sphinx不一样 +------+--------+------------+------+ | id | weight | user_id | u_id | +------+--------+------------+------+ | 3 | 2230 | 1311895260 | 62 | | 5 | 2230 | 1311895260 | 33 | | 4 | 1304 | 1311895262 | 0 | | 6 | 1304 | 1311895262 | 34 | +------+--------+------------+------+ 4 rows in set (0.00 sec) mysql> show META; //上次检索的信息 +---------------+-------+ | Variable_name | Value | +---------------+-------+ | total | 3 | | total_found | 3 | | time | 0.000 | | keyword[0] | test | | docs[0] | 3 | | hits[0] | 5 | +---------------+-------+ 6 rows in set (0.00 sec) mysql> show tables; //这里的表其实不是真表,也不是create table创建出来的,是sphinx索引 +--------------+-------------+ | Index | Type | +--------------+-------------+ | dist1 | distributed | | myorder | local | | rt | rt | | tank_test | rt | | test1 | local | | test1stemmed | local | +--------------+-------------+ 6 rows in set (0.00 sec)
二,创建sphinx索引
1,修改/usr/local/sphinx/etc/sphinx.conf
# vim /usr/local/sphinx/etc/sphinx.conf //添加以下内容 index tank_test { type = rt path = /usr/local/sphinx/var/data/rt charset_dictpath = /usr/local/mmseg3/etc/ charset_type = zh_cn.utf-8 ngram_len = 0 rt_field = name rt_field = title rt_field = sub_title rt_attr_uint = user_id rt_attr_uint = uid }
在这里要注意,rt_field是检索字段,rt_attr_uint是返回字段
2,重启sphinx
# pkill -9 searchd # /usr/local/sphinx/bin/indexer --config /usr/local/sphinx/etc/sphinx.conf --all # /usr/local/sphinx/bin/searchd --config /usr/local/sphinx/etc/sphinx.conf
3,插入数据,并查看
mysql> show tables; +--------------+-------------+ | Index | Type | +--------------+-------------+ | dist1 | distributed | | rt | rt | | tank_test | rt | //新增加的索引 | test1 | local | | test1stemmed | local | +--------------+-------------+ 5 rows in set (0.00 sec) mysql> desc tank_test; +-----------+---------+ | Field | Type | +-----------+---------+ | id | bigint | | name | field | | title | field | | sub_title | field | | user_id | integer | | u_id | integer | +-----------+---------+ 6 rows in set (0.00 sec) mysql> insert into tank_test values (3,'坦克','tank is 坦克','技术总监',1311895260,33); mysql> insert into tank_test values (4,'tank张','tank is 坦克','技术总监',1311895262,34); mysql> select * from tank_test where match('坦克'); //匹配搜索的字段是rt_field +------+--------+------------+------+ | id | weight | user_id | u_id | //返回的字段是rt_attr_uint +------+--------+------------+------+ | 3 | 2230 | 1311895260 | 33 | | 4 | 1304 | 1311895262 | 34 | +------+--------+------------+------+ 2 rows in set (0.00 sec)
id和weight是系统自带的返回字段
到这儿索引就创建好了,show tables的时候是可以看新建的tank_test,用phpmyadmin或者其他mysql数据库连接工具根本看不到,原因是他根本不是真实的表。sphinx到底能不能用真实的表呢?
三,创建表,并添加索引
1,创建真实的表,插入数据
CREATE TABLE IF NOT EXISTS `orders` ( `id` int(11) NOT NULL AUTO_INCREMENT, `user_id` int(11) NOT NULL , `username` varchar(20) NOT NULL, `create_time` datetime NOT NULL, `product_name` varchar(20) NOT NULL, `summary` text NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ; INSERT INTO `orders` (`user_id` ,`username` ,`create_time` ,`product_name` ,`summary`) VALUES ('1311895262','张三','2014-08-01 00:24:54','tank is 坦克','技术总监'), ('1311895263','tank张二','2014-08-01 00:24:54','tank is 坦克','技术经理'), ('1311895264','tank张一','2014-08-01 00:24:54','tank is 坦克','DNB经理'), ('1311895265','tank张','2014-08-01 00:24:54','tank is 坦克','运维总监');
在这里要注意,是连接mysql的3306端口,不是连接coreseek sphinx的9306
2,修改/usr/local/sphinx/etc/sphinx.conf,添加以下内容
source order { type = mysql sql_host = localhost sql_user = root sql_pass = sql_db = test sql_query_pre = SET NAMES utf8 sql_query = \ SELECT id, user_id, username, UNIX_TIMESTAMP(create_time) AS create_time, product_name, summary \ FROM orders sql_attr_uint = user_id sql_attr_timestamp = create_time sql_ranged_throttle = 0 sql_query_info = SELECT * FROM orders WHERE id=$id } index myorder { source = order path = /usr/local/sphinx/var/data/myorder docinfo = extern mlock = 0 morphology = none min_word_len = 1 charset_dictpath = /usr/local/mmseg3/etc/ charset_type = zh_cn.utf-8 ngram_len = 0 html_strip = 0 }
3,重启sphinx
# pkill -9 searchd # /usr/local/sphinx/bin/indexer --config /usr/local/sphinx/etc/sphinx.conf --all # /usr/local/sphinx/bin/searchd --config /usr/local/sphinx/etc/sphinx.conf
4,切换到9306,检索测试
mysql> show tables; +--------------+-------------+ | Index | Type | +--------------+-------------+ | dist1 | distributed | | myorder | local | | rt | rt | | tank_test | rt | | test1 | local | | test1stemmed | local | +--------------+-------------+ 6 rows in set (0.00 sec) mysql> desc myorder; +--------------+-----------+ | Field | Type | +--------------+-----------+ | id | bigint | | username | field | | product_name | field | | summary | field | | user_id | integer | | create_time | timestamp | +--------------+-----------+ 6 rows in set (0.00 sec) mysql> select * from myorder where match('坦克'); +------+--------+------------+-------------+ | id | weight | user_id | create_time | +------+--------+------------+-------------+ | 5 | 1304 | 1311895262 | 1407081600 | | 6 | 1304 | 1311895263 | 1406823894 | | 7 | 1304 | 1311895264 | 1406823894 | | 8 | 1304 | 1311895265 | 1406823894 | +------+--------+------------+-------------+ 4 rows in set (0.00 sec)



MySQL's position in databases and programming is very important. It is an open source relational database management system that is widely used in various application scenarios. 1) MySQL provides efficient data storage, organization and retrieval functions, supporting Web, mobile and enterprise-level systems. 2) It uses a client-server architecture, supports multiple storage engines and index optimization. 3) Basic usages include creating tables and inserting data, and advanced usages involve multi-table JOINs and complex queries. 4) Frequently asked questions such as SQL syntax errors and performance issues can be debugged through the EXPLAIN command and slow query log. 5) Performance optimization methods include rational use of indexes, optimized query and use of caches. Best practices include using transactions and PreparedStatemen

MySQL is suitable for small and large enterprises. 1) Small businesses can use MySQL for basic data management, such as storing customer information. 2) Large enterprises can use MySQL to process massive data and complex business logic to optimize query performance and transaction processing.

InnoDB effectively prevents phantom reading through Next-KeyLocking mechanism. 1) Next-KeyLocking combines row lock and gap lock to lock records and their gaps to prevent new records from being inserted. 2) In practical applications, by optimizing query and adjusting isolation levels, lock competition can be reduced and concurrency performance can be improved.

MySQL is not a programming language, but its query language SQL has the characteristics of a programming language: 1. SQL supports conditional judgment, loops and variable operations; 2. Through stored procedures, triggers and functions, users can perform complex logical operations in the database.

MySQL is an open source relational database management system, mainly used to store and retrieve data quickly and reliably. Its working principle includes client requests, query resolution, execution of queries and return results. Examples of usage include creating tables, inserting and querying data, and advanced features such as JOIN operations. Common errors involve SQL syntax, data types, and permissions, and optimization suggestions include the use of indexes, optimized queries, and partitioning of tables.

MySQL is an open source relational database management system suitable for data storage, management, query and security. 1. It supports a variety of operating systems and is widely used in Web applications and other fields. 2. Through the client-server architecture and different storage engines, MySQL processes data efficiently. 3. Basic usage includes creating databases and tables, inserting, querying and updating data. 4. Advanced usage involves complex queries and stored procedures. 5. Common errors can be debugged through the EXPLAIN statement. 6. Performance optimization includes the rational use of indexes and optimized query statements.

MySQL is chosen for its performance, reliability, ease of use, and community support. 1.MySQL provides efficient data storage and retrieval functions, supporting multiple data types and advanced query operations. 2. Adopt client-server architecture and multiple storage engines to support transaction and query optimization. 3. Easy to use, supports a variety of operating systems and programming languages. 4. Have strong community support and provide rich resources and solutions.

InnoDB's lock mechanisms include shared locks, exclusive locks, intention locks, record locks, gap locks and next key locks. 1. Shared lock allows transactions to read data without preventing other transactions from reading. 2. Exclusive lock prevents other transactions from reading and modifying data. 3. Intention lock optimizes lock efficiency. 4. Record lock lock index record. 5. Gap lock locks index recording gap. 6. The next key lock is a combination of record lock and gap lock to ensure data consistency.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

Zend Studio 13.0.1
Powerful PHP integrated development environment

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Dreamweaver CS6
Visual web development tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.