mysql数据库的编译安装

mysql5.1之前编译mysql使用的是make工具,编译步骤如下:

./configure --prefix=

make &&make install


mysql5.5之后编译mysql使用的是cmake工具,编译步骤如下:

cmake .

查看帮助使用: cmake -LH 或ccmake .


1.创建mysql用户及安装依赖软件包.

[root@mytest2 mnt]# groupadd -r mysql

[root@mytest2 mnt]# useradd -r -g mysql  -s /sbin/nolog mysql

[root@mytest2 mnt]# id mysql

uid=101(mysql) gid=102(mysql) groups=102(mysql)


安装mysql依赖的软件包

yum install gcc gcc-c++ ncurses  ncurses-devel  openssl openssl-devel zlib bison cmake

到www.mysql.com下载mysql的源码包.

2.编译安装mysql

cd mysql源码目录

cmake .  -LH

若产生异常,可以删除CMakeCache.txt,重新执行cmake . -LH


[root@mytest2 mysql-5.5.38]# cmake . -LH

-- Running cmake version 2.6.4

-- MySQL 5.5.38

-- Packaging as: mysql-5.5.38-Linux-x86_64

-- Library mysqlclient depends on OSLIBS -lpthread;m;rt;dl

Warning: Bison executable not found in PATH

-- Configuring done

-- Generating done

-- Build files have been written to: /tmp/mysql-5.5.38

-- Cache values

// Choose the type of build, options are: None(CMAKE_CXX_FLAGS or

CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel

CMAKE_BUILD_TYPE:STRING=RelWithDebInfo


// install prefix

CMAKE_INSTALL_PREFIX:PATH=/usr/local/mysql


// Set to true if this is a community build

COMMUNITY_BUILD:BOOL=ON


// Enable profiling

ENABLED_PROFILING:BOOL=ON


// Enable debug sync (debug builds only)

ENABLE_DEBUG_SYNC:BOOL=ON


// Enable gcov (debug, Linux builds only)

ENABLE_GCOV:BOOL=OFF


// Installation directory layout. Options are: STANDALONE (as in zip or tar.gz installer), RPM, DEB, SVR4

INSTALL_LAYOUT:STRING=STANDALONE


// default MySQL data directory

MYSQL_DATADIR:PATH=/usr/local/mysql/data


// MySQL maintainer-specific development environment

MYSQL_MAINTAINER_MODE:BOOL=OFF


// PATH to MySQL TMP dir. Defaults to the P_tmpdir macro in <stdio.h>

TMPDIR:PATH=P_tmpdir


// Link ARCHIVE statically to the server

WITH_ARCHIVE_STORAGE_ENGINE:BOOL=OFF


// Enable address sanitizer

WITH_ASAN:BOOL=OFF


// Link BLACKHOLE statically to the server

WITH_BLACKHOLE_STORAGE_ENGINE:BOOL=OFF


// Use dbug/safemutex

WITH_DEBUG:BOOL=OFF


// Compile MySQL with embedded server

WITH_EMBEDDED_SERVER:BOOL=OFF


// Options are: none, complex, all

WITH_EXTRA_CHARSETS:STRING=all


// Link FEDERATED statically to the server

WITH_FEDERATED_STORAGE_ENGINE:BOOL=OFF


// Link INNOBASE statically to the server

WITH_INNOBASE_STORAGE_ENGINE:BOOL=ON


// Use bundled libedit

WITH_LIBEDIT:BOOL=ON


// Compile with tcp wrappers support

WITH_LIBWRAP:BOOL=OFF


// Link PARTITION statically to the server

WITH_PARTITION_STORAGE_ENGINE:BOOL=ON


// Link PERFSCHEMA statically to the server

WITH_PERFSCHEMA_STORAGE_ENGINE:BOOL=ON


// Generate PIC objects

WITH_PIC:BOOL=OFF


// Use bundled readline

WITH_READLINE:BOOL=OFF


// Options are : no, bundled, yes (prefer os library if present otherwise use bundled), system (use os library)

WITH_SSL:STRING=no


// Compile MySQL with unit tests

WITH_UNIT_TESTS:BOOL=ON


// Valgrind instrumentation

WITH_VALGRIND:BOOL=OFF


// Use bundled zlib

WITH_ZLIB:STRING=bundled


[root@mytest2 mysql-5.5.38]# 


2.1 执行编译.

cmake . -DCMAKE_INSTALL_PREFIX:PATH=/usr/local/mysql \

-DMYSQL_DATADIR:PATH=/data/mysql \

-DSYSCONFDIR=/etc \

-DWITH_INNOBASE_STORAGE_ENGINE:BOOL=ON \

-DWITH_ARCHIVE_STORAGE_ENGINE:BOOL=On \

-DWITH_BLACKHOLE_STORAGE_ENGINE:BOOL=On \

-DWITH_EXTRA_CHARSETS:STRING=all \

-DWITH_READLINE:BOOL=On \

-DWITH_SSL:STRING=system \

-DWITH_ZLIB=system \

-DWITH_LIBWRAP:BOOL=OFF \

-DENABLED_PROFILING:BOOL=ON \

-DMYSQL_UNIX_ADDR=/tmp/mysql.sock \

-DDEFAULT_CHARSET=utf8 \

-DDEFAULT_COLLATION=utf8_general_ci

make && make install

2.2初始化mysql.

chown -R root:mysql /usr/local/mysql

cd /usr/local/mysql

scripts/mysql_install_db --user=mysql --datadir=/data/mysql

cp support-files/my-medium.cnf /etc/my.cnf

cp support-files/mysql.server /etc/init.d/mysqld

echo "export PATH=$PATH:/usr/local/mysql/bin;" >/etc/profile.d/mysql.sh

. /etc/profile.d/mysql.sh

vi /etc/my.cnf,在[mysqld]中增加datadir=/data/mysql 与innodb_file_per_table =on

bin/mysqld_safe  --user=mysql &

chkconfig --add mysqld

chkconfig mysqld on

service mysqld status


2.3验证并删除匿名用户.

[root@mytest2 mysql]# service mysqld status

MySQL running (1581)[确定]

[root@mytest2 mysql]# mysql

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 1

Server version: 5.5.38-log Source distribution


Copyright (c) 2000, 2014, 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> show databases;

+--------------------+

| Database           |

+--------------------+

| information_schema |

| mysql              |

| performance_schema |

| test               |

+--------------------+

4 rows in set (0.01 sec)


mysql> select user,host,password from mysql.user;

+------+-----------+----------+

| user | host      | password |

+------+-----------+----------+

| root | localhost |          |

| root | mytest2   |          |

| root | 127.0.0.1 |          |

| root | ::1       |          |

|      | localhost |          |

|      | mytest2   |          |

+------+-----------+----------+

6 rows in set (0.01 sec)


mysql> drop user ‘‘@‘localhost‘;

Query OK, 0 rows affected (0.00 sec)


mysql> drop user ‘‘@mytest2;

Query OK, 0 rows affected (0.00 sec)


mysql> drop user ‘root‘@‘::1‘;

Query OK, 0 rows affected (0.00 sec)


mysql> select user,host,password from mysql.user;

+------+-----------+----------+

| user | host      | password |

+------+-----------+----------+

| root | localhost |          |

| root | mytest2   |          |

| root | 127.0.0.1 |          |

+------+-----------+----------+

3 rows in set (0.00 sec)

至此mysql安装完成.


mysql默认配置文件查找路径顺序如下:

/etc/my.cnf

/etc/mysql/my.cnf

$MYSQL_HOME/my.cnf

~/.my.cnf

启动mysql时指定的--default_extra路径.


异常的处理方法: 错误:‘SSL_OP_NO_COMPRESSION’ 未声明 (在此函数内第一次使用)

1.下载较新的openssl.

2.编译安装

./config shared zlib-dynamic --prefix=/usr/local/openssl

make && make install

3.配置

mv /usr/bin/openssl /usr/bin/openssl_bak

mv /usr/lib/include/openssl /usr/lib/include/openssl_bak

mv /usr/lib/libssl.so  /usr/lib/libssl.so_bak

mv /usr/lib64/libssl.so /usr/lib64/libssl.so_bak


ln -s /usr/local/openssl/bin/openssl /usr/bin/openssl

ln -s /usr/local/openssl/include/openssl   /usr/include/openssl

ln -s /usr/local/openssl/lib/libssl.so /usr/lib/libssl.so

ln -s /usr/local/openssl/lib/libssl.so /usr/lib64/libssl.so


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

ldconfig -v

4.配置完成后,重新编译mysql即可.


本文出自 “webseven” 博客,请务必保留此出处http://webseven.blog.51cto.com/4388012/1530791

mysql数据库的编译安装,布布扣,bubuko.com

mysql数据库的编译安装

上一篇:阿里云配置mysql远程连接


下一篇:UCenter info: MySQL Query Error的解决方法----For Discuz!