Home Database Mysql Tutorial Linux下MySQL 5.5的Cmake安装以及Sphinx结合

Linux下MySQL 5.5的Cmake安装以及Sphinx结合

Jun 07, 2016 pm 05:04 PM
sphinx

Linux下MySQL 5.5的Cmake安装以及Sphinx结合

首先需要添加mysql用户组和mysql用户
   groupadd mysql
   useradd -g mysql mysql
   passwd -u mysql

1. 安装需要的软件包
   yum install gcc gcc-c++ libtool autoconf automake imake libxml2-devel expat-devel
   yum install ncurses-devel make
   yum install make
   yum install cmake bison
  

2. 下载mysql源码包后解压到指定目录
    mkdir /data/
    cd /data/ #把安装包放入到这个文件夹
    tar -zxvf mysql-5.5.14.tar.gz

3. 进入解压后的源码包
   cd mysql-5.5.14

4. cmake进行编译(首先要创建数据文件夹和安装文件夹, 如果路径不存在)
   cmake . \
   -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
   -DMYSQL_DATADIR=/var/tmp/mysql/ \
   -DMYSQL_UNIX_ADDR=/var/tmp/mysql/mysqld.sock \
   -DDEFAULT_CHARSET=utf8 \
   -DEXTRA_CHARSETS=all \
   -DDEFAULT_COLLATION=utf8_general_ci \
   -DWITH_MYISAM_STORAGE_ENGINE=1 \
   -DWITH_SPHINX_STORAGE_ENGINE=1 \
   -DWITH_INNOBASE_STORAGE_ENGINE=1 \
   -DWITH_MEMORY_STORAGE_ENGINE=1 \
   -DWITH_READLINE=1 \
   -DENABLED_LOCAL_INFILE=1 \
   -DMYSQL_USER=mysql

5. make

6. make install

7. 配置文件
   cp support-files/my-medium.cnf /etc/my.cnf
   cp support-files/mysql.server /etc/init.d/mysqld
   chmod 755 /etc/init.d/mysqld

8. 初始化数据库
   如果出现这个错误[ERROR] Fatal error: Can't open and lock privilege tables: Table 'mysql.host' doesn't exist
   是因为没有指定数据文件位置.
   ./scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/var/tmp/mysql/ &

9. 授权
   chown -R mysql:mysql /usr/local/mysql/
   chown -R mysql:mysql /var/tmp/mysql/

10. 启动数据库
   service mysqld start

11. 设置到环境变量
   vi /etc/profile
   export PATH="$PATH:/usr/local/mysql/bin"
  
/usr/local/mysql/bin/mysqladmin -u root password 'new-password'
/usr/local/mysql/bin/mysqladmin -u root -h namenode password 'new-password'


12. mysql到此基本告一段落, 谢谢大家

[root@db001 lib]# /usr/local/sphinx/bin/indexer -all
/usr/local/sphinx/bin/indexer: error while loading shared libraries: libmysqlclient.so.18: cannot open shared object file: No such file or directory


echo "/usr/local/mysql/lib/" >> /etc/ld.so.conf
ldconfig

1.

解压sphinx源码包:

$ tar xzvf sphinx-0.9.8.1.tar.gz
$ cd sphinx

2.

运行configure配置程序:

$ ./configure [options]

有一些参数可以在配置的时候指定,主要如下:
* –prefix, 指定sphinx 安装到系统的那个位置; 例如 –prefix=/usr/local/sphinx
* –with-mysql, mysql的安装目录,指定如果自动侦查mysql的相关库文件失败后到哪个目录查找
* –with-pgsql, 同上,只是用于pgsql的
完整的配置命令如下:./configure –prefix=/usr/local/sphinx –with-mysql=/usr/local/mysql
3. 编译:

$ make

在这个步骤,可能遇到一个问题,就是报 sphinx undefined reference to ‘libiconv’ 的错误,解决办法是修改 /src/MakeFile(注 意是src下的Makefile不是csft下的Makefile),编辑LIBS = -lm -lexpat 后面添加-liconv,即将该行该为:
LIBS = -lm -lexpat -liconv -L/usr/local/lib

4. 安装

$ make install

如果编译中没有产生错误,这个步骤应该不会遇到问题。如果完成后未正确安装,就要回去找make过程中遇到的错误了。

5. 运行测试

$ cd /usr/local/sphinx/etc
$ cp sphinx.conf.dist sphinx.conf
$ vi sphinx.conf

这里,sphinx提供了一个简单的例子,基本步骤是先将/sphinx/etc下面的 sphinx.conf.dist重命名为sphinx.conf,然后修改sphinx.conf其中的配置,主要是修改你服务器上面的mysql的用户名、密码、使用的数据库等。修改的位置是sphinx.conf的source src1下面几行。

$ mysql -u test

这里是导入sphinx准备的测试数据,我们把数据导入到mysql的test数据库中。当然,这里的数据库要和你上面的配置文件(sphinx.conf)中指定的sql_db值相同。注意,运行这个命令的话,如果你的mysql命令没有加入到环境变量中,就需要用完整路径,同时可能需要输入密码。比如你的mysql安装在 /usr/local/mysql 目录中,root账户的密码是 xxxxxx ,那么命令应该调整为:
$ /usr/local/mysql/bin/mysql -uroot -pxxxxxx test

$ cd /usr/local/sphinx/etc
$ /usr/local/sphinx/bin/indexer –all

这个命令是建立索引,,当然数据基础是刚刚导入的 example.sql的数据,如果这里出错,最大的可能是你的sphinx.conf中的数据库配置错了,你需要回去检查并修正。但是,还有可能出现 sphinx必须的库文件无法找到,例如出现以下两种错误:
/usr/local/sphinx/bin/indexer: error while loading shared libraries: libmysqlclient.so.15: cannot open shared object file: No such file or directory
/usr/local/sphinx/bin/indexer: error while loading shared libraries: libiconv.so.2: cannot open shared object file: No such file or directory
这主要是因为你安装了一些库后,没有能够配置相应的环境变量。你可以通过建立连接的方式修正这个问题,运行如下命令:
ln -s /usr/local/mysql/lib/libmysqlclient.so.15 /usr/lib/libmysqlclient.so.15
ln -s /usr/local/lib/libiconv.so.2 /usr/lib/libiconv.so.2
这里我假设你相应的软件包安装在/usr/local/xxx 目录下,如果你不是安装在相应目录下,你就需要使用你自己的路径。如果你没有安装libiconv软件包,则需要安装下,这个安装比较简单,就不多说了。
如果还出现类似错误,照上面的方法修正。

$ cd /usr/local/sphinx/etc
$ /usr/local/sphinx/bin/search test

上面的命令是搜索测试,测试的关键词就是 test 了,如果成功的话,你应该看到搜到的结果,出现字串“index ‘test1′: query ‘test ‘: returned 3 matches of 3 total in 0.000 sec”,后面跟的是结果表示成功了。

$ cd /usr/local/sphinx/etc
$ /usr/local/sphinx/bin/searchd

运行上面的命令,你就启动了sphinx进程了,如果没什么错误,可以通过ps -aux|grep ‘3312′ 找到sphinx进程了。哈哈,大功告成!

linux

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to use php extension Sphinx for full text search How to use php extension Sphinx for full text search Jul 29, 2023 am 10:05 AM

How to use PHP extension Sphinx for full-text search Full-text search is one of the common requirements in modern web applications. In order to satisfy users' efficient query and retrieval of data, we can use Sphinx, a powerful open source search engine, to implement the full-text search function. Sphinx is written in C++ and provides PHP extensions to facilitate our use in PHP projects. This article will introduce how to use the PHP extension Sphinx for full-text search

Sphinx PHP application guide to implement full-text search Sphinx PHP application guide to implement full-text search Oct 03, 2023 am 08:37 AM

Introduction to the PHP application guide for implementing full-text search with Sphinx: In modern Web applications, the full-text search function has become an essential feature. Because users often search and match the content they need by entering keywords. In order to provide efficient and accurate search results, we need a powerful search engine. As an open source full-text search engine, Sphinx provides a perfect search solution for PHP. This article will introduce how to use Sphinx to implement

Sphinx PHP application skills in natural language processing Sphinx PHP application skills in natural language processing Oct 03, 2023 am 09:53 AM

SphinxPHP application skills in natural language processing require specific code examples. With the development of the Internet and the advancement of artificial intelligence technology, natural language processing (Natural Language Processing, NLP) has become an important research direction in computer science. The goal of natural language processing is to enable computers to understand, interpret and generate natural language, making the communication between humans and machines more convenient and intelligent. In natural language processing, text retrieval is a very important

Sphinx implements real-time search effects for PHP projects Sphinx implements real-time search effects for PHP projects Oct 03, 2023 am 09:16 AM

Sphinx is an open source full-text search engine that can quickly and efficiently realize search and retrieval of large-scale data. In PHP projects, using Sphinx can achieve real-time search effects and improve user experience and search speed. This article will introduce how to use Sphinx in PHP projects and provide specific code examples. 1. Install Sphinx To achieve real-time search effects in PHP projects, you first need to install Sphinx. It can be found in Sphinx official website

Analysis of PHP implementation method of Sphinx distributed search Analysis of PHP implementation method of Sphinx distributed search Oct 03, 2023 am 08:49 AM

Analysis of the PHP implementation method of Sphinx distributed search Introduction: In today's Internet era, search engines have become one of the main ways for people to obtain information. In order to provide more efficient and accurate search results, some large-scale websites or applications usually use distributed search engines to process search requests. Sphinx is a well-known distributed search engine with good performance and scalability. This article will introduce how to use PHP to implement Sphinx distributed search and provide specific code examples.

Research on PHP implementation method of Sphinx high-availability search Research on PHP implementation method of Sphinx high-availability search Oct 03, 2023 am 09:41 AM

Research introduction on PHP implementation method of Sphinx high-availability search: Sphinx is an open source full-text search engine, which provides fast, accurate and scalable search solutions. Integrating Sphinx into PHP websites can achieve highly available search functions. This article will explore how Sphinx is implemented in PHP and provide specific code examples. 1. Introduction to Sphinx Sphinx is a full-text search engine developed in C++. It focuses on fast and

Sphinx implements fast search and cache optimization for PHP projects Sphinx implements fast search and cache optimization for PHP projects Oct 03, 2023 am 09:01 AM

Sphinx is an open source full-text search engine that can quickly process large amounts of data and provide efficient search capabilities. Using Sphinx in PHP projects can achieve fast search and cache optimization, improving project performance and user experience. This article will introduce how to integrate Sphinx in a PHP project and illustrate its usage and advantages through specific code examples. 1. Sphinx installation and configuration To use Sphinx, you first need to install and configure it on the server.

Sphinx's practical approach to PHP language search optimization Sphinx's practical approach to PHP language search optimization Oct 03, 2023 am 09:24 AM

Sphinx's practical approach to PHP language search optimization requires specific code examples Summary: Sphinx is a powerful open source search engine tool that can be used to implement efficient search functions in web applications. This article will introduce how to use Sphinx for PHP language search optimization and provide detailed code examples. Introduction: With the rapid development of the Internet, users' demand for search functions is also increasing. Efficient search for large-scale data and accuracy of search results,

See all articles