---
title: "centos cmake 安装 mysql-5.5.16 附配置文件"
author: "oraclestudy"
date: "2011-10-31T12:31:00Z"
tags: []
slug: "centos-cmake-mysql-5-5-16"
draft: false
lastmod: "2011-11-03T10:08:14Z"
id: 1232887
url: "https://oraclestudy.iteye.com/blog/1232887"
---

mysql从5.5之后源码安装需要使用cmake:

To install MySQL from source, your system must have the following tools, regardless of installation method:

- **CMake**, which is used as the build framework on all platforms.**CMake** can be downloaded from[http://www.cmake.org](http://www.cmake.org/).
- A good **make** program. Although some platforms come with their own**make** implementations, it is highly recommended that you use GNU**make** 3.75 or newer. It may already be available on your system as**gmake**. GNU**make** is available from[http://www.gnu.org/software/make/](http://www.gnu.org/software/make/).
- A working ANSI C++ compiler. GCC 4.2.1 or later, Sun Studio 10 or later, Visual Studio 2008 or later, and many current vendor-supplied compilers are known to work.
- Perl is needed if you intend to run test scripts. Most Unix-like systems include Perl. On Windows, you can use a version such as ActiveState Perl.

yum 安装 gcc,gcc-c++,cmake,bison(GNU),使用 centos6.0 自带的perl和openssl

添加mysql组和mysql用户

/usr/sbin/groupaddmysql  
/usr/sbin/useradd-gmysqlmysql

将mysql和data文件安装到不同的物理磁盘上

cmake -DCMAKE\_INSTALL\_PREFIX=/opt/soft/mysql \\  
\-DMYSQL\_DATADIR=/home/soft/mysql/data \\  
\-DMYSQL\_UNIX\_ADDR=/opt/soft/mysql/mysql.sock \\  
\-DMYSQL\_TCP\_PORT=3306 \\  
\-DDEFAULT\_CHARSET=utf8 \\  
\-DDEFAULT\_COLLATION=utf8\_general\_ci \\  
\-DEXTRA\_CHARSETS=all \\  
\-DWITH\_EMBEDDED\_SERVER=0 \\  
\-DWITH\_MYISAM\_STORAGE\_ENGINE=1 \\  
\-DWITH\_INNOBASE\_STORAGE\_ENGINE=1 \\  
\-DWITH\_MEMORY\_STORAGE\_ENGINE=1 \\  
\-DWITH\_BLACKHOLE\_STORAGE\_ENGINE=1 \\  
\-DWITH\_READLINE=1 \\  
\-DENABLED\_LOCAL\_INFILE=1 \\  
\-DMYSQL\_USER=mysql \\  
\-DWITH\_DEBUG=0 \\  
\-DWITH\_SSL=yes

报错:

-- Could NOT find Curses (missing: CURSES\_LIBRARY CURSES\_INCLUDE\_PATH)  
CMake Error at cmake/readline.cmake:82 (MESSAGE):  
Curses library not found. Please install appropriate package,

remove CMakeCache.txt and rerun cmake.On Debian/[Ubuntu](http://www.linuxidc.com/topicnews.aspx?tid=2 "Ubuntu") , package name is libncurses5-dev ,

on [RedHat](http://www.linuxidc.com/topicnews.aspx?tid=10 "RedHat") and derivates it is ncurses-devel.  
Call Stack (most recent call first):  
cmake/readline.cmake:126 (FIND\_CURSES)  
cmake/readline.cmake:216 (MYSQL\_USE\_BUNDLED\_LIBEDIT)  
CMakeLists.txt:256 (MYSQL\_CHECK\_READLINE)

-- Configuring incomplete, errors occurred!

=======================

没有安装 ncurses-devel

yum安装之后 还是报错,找运维高手才知道 cmake会产生CMakeCache.txt文件,每次cmake之前需要删除它....

ok,一切正常

echo $?

输出结果为0

make

make install

安装成功

chown mysql:mysql /home/soft/mysql -R

chown mysql:mysql /opt/soft/mysql/ -R

初始化数据库

cd /opt/soft/mysql/

/opt/soft/mysql/scripts/mysql\_install\_db \\--defaults-file=/opt/soft/mysql/config/my.cnf \\ --basedir=/opt/soft/mysql\\ --datadir=/home/soft/mysql/data \\ --user=mysql  
Installing MySQL system tables...  
OK  
Filling help tables...  
OK

To start mysqld at boot time you have to copy  
support-files/mysql.server to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !  
To do so, start the server, then issue the following commands:

./bin/mysqladmin -u root password 'new-password'  
./bin/mysqladmin -u root -h c60h.localdomain password 'new-password'

Alternatively you can run:  
./bin/mysql\_secure\_installation

which will also give you the option of removing the test  
databases and anonymous user created by default. This is  
strongly recommended for production servers.

See the manual for more instructions.

You can start the MySQL daemon with:  
cd . ; ./bin/mysqld\_safe &

You can test the MySQL daemon with mysql-test-run.pl  
cd ./mysql-test ; perl mysql-test-run.pl

Please report any problems with the ./bin/mysqlbug script!

===============================

之所以要安装mysql5.5.16是想将Percona-5.5.16中的xtraDB安装到mysql中,替换了storage中的innobase,结果make步骤中报错,只能是单独安装Percona了.

=================================

启动

/opt/soft/mysql/bin/mysqld\_safe --defaults-file=/opt/soft/mysql/config/my.cnf --user=mysql &  
\[1] 25812  
\# 111031 13:18:55 mysqld\_safe Logging to '/home/soft/mysql/data/c60h.localdomain.err'.  
111031 13:18:55 mysqld\_safe Starting mysqld daemon with databases from /home/soft/mysql/data  
^C  
\# netstat -antp  
Active Internet connections (servers and established)  
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name  
tcp 0 0 0.0.0.0:50341 0.0.0.0:* LISTEN 1409/rpc.statd  
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 26217/mysqld  
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 1340/rpcbind  
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1619/sshd  
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 1121/cupsd  
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1695/master  
tcp 0 52 192.168.161.141:22 192.168.161.1:54674 ESTABLISHED 1820/sshd: admin [p  
tcp 0 0 :::42759 :::* LISTEN 1409/rpc.statd  
tcp 0 0 :::111 :::* LISTEN 1340/rpcbind  
tcp 0 0 :::22 :::* LISTEN 1619/sshd

tcp 0 0 ::1:631 :::* LISTEN 1121/cupsd

配置mysql用户  
/opt/soft/mysql/bin/mysqladmin -u root password 123456  
/opt/soft/mysql/bin/mysql  
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)  
/opt/soft/mysql/bin/mysql -p123456  
Welcome to the MySQL monitor. Commands end with ; or \\g.  
Your MySQL connection id is 5  
Server version: 5.5.16-log Source distribution

Copyright (c) 2000, 2011, 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&gt; use mysql  
Reading table information for completion of table and column names  
You can turn off this feature to get a quicker startup with -A

Database changed  
mysql&gt; select host,user,password from user;  
+------------------+------+-------------------------------------------+  
| host | user | password |  
+------------------+------+-------------------------------------------+  
| localhost | root | \*6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |  
| c60h.localdomain | root | |  
| 127.0.0.1 | root | |  
| ::1 | root | |  
| localhost | | |  
| c60h.localdomain | | |  
+------------------+------+-------------------------------------------+  
6 rows in set (0.00 sec)

mysql&gt; delete from user where LENGTH(password)&lt;10;  
Query OK, 5 rows affected (0.00 sec)

mysql&gt; select host,user,password from user;  
+-----------+------+-------------------------------------------+  
| host | user | password |  
+-----------+------+-------------------------------------------+  
| localhost | root | \*6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |  
+-----------+------+-------------------------------------------+  
1 row in set (0.00 sec)

mysql&gt; grant all on \*.* to 'admin'@'192.168.%' identified by '123456';  
Query OK, 0 rows affected (0.00 sec)

mysql&gt; select user,host,password from user;  
+-------+-----------+-------------------------------------------+  
| user | host | password |  
+-------+-----------+-------------------------------------------+  
| root | localhost | \*6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |  
| admin | 192.168.% | \*6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |  
+-------+-----------+-------------------------------------------+  
2 rows in set (0.00 sec)

===================

root用户只能本机登陆

admin 只能局域网登陆

==============================

开启 3306 端口

vi /etc/sysconfig/iptables

-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT

service iptables restart

重启 iptables 生效

========================

配置文件

cat config/my.cnf  
\[client]  
#password = your\_password  
port = 3306  
socket = /opt/soft/mysql/mysql.sock  
default-character-set = utf8

\[mysql]  
default-character-set = utf8

\[mysqld]  
character-set-server = utf8  
datadir = /home/soft/mysql/data  
tmpdir = /dev/shm  
port = 3306  
socket = /opt/soft/mysql/mysql.sock  
pid-file = /opt/soft/mysql/601.localdomain.pid  
skip-external-locking  
key\_buffer\_size = 16K  
max\_allowed\_packet = 1M  
table\_open\_cache = 4  
sort\_buffer\_size = 64K  
read\_buffer\_size = 256K  
read\_rnd\_buffer\_size = 256K  
net\_buffer\_length = 2K  
thread\_stack = 128K

default-storage-engine = innodb  
innodb\_buffer\_pool\_size = 128M  
innodb\_data\_home\_dir = /home/soft/mysql/data  
innodb\_data\_file\_path = ibdata1:10M:autoextend  
innodb\_log\_group\_home\_dir = /opt/soft/mysql/log  
innodb\_log\_file\_size = 512M  
innodb\_log\_files\_in\_group = 3  
innodb\_lock\_wait\_timeout = 60  
innodb\_flush\_log\_at\_trx\_commit = 2

#skip-networking  
server-id = 601

log-slave-updates  
log-bin = /opt/soft/mysql/binlog/mysql-bin  
relay-log = /opt/soft/mysql/binlog/mysql-relay-bin  
#binlog\_format=mixed

\# Causes updates to non-transactional engines using statement format to be  
\# written directly to binary log. Before using this option make sure that  
\# there are no dependencies between transactional and non-transactional  
\# tables such as in the statement INSERT INTO t\_myisam SELECT * FROM  
\# t\_innodb; otherwise, slaves may diverge from the master.  
#binlog\_direct\_non\_transactional\_updates=TRUE

\# Uncomment the following if you are using InnoDB tables  
#innodb\_data\_home\_dir = /var/lib/mysql  
#innodb\_data\_file\_path = ibdata1:10M:autoextend  
#innodb\_log\_group\_home\_dir = /var/lib/mysql  
\# You can set ..\_buffer\_pool\_size up to 50 - 80 %  
\# of RAM but beware of setting memory usage too high  
#innodb\_buffer\_pool\_size = 16M  
#innodb\_additional\_mem\_pool\_size = 2M  
\# Set ..\_log\_file\_size to 25 % of buffer pool size  
#innodb\_log\_file\_size = 5M  
#innodb\_log\_buffer\_size = 8M  
#innodb\_flush\_log\_at\_trx\_commit = 1  
#innodb\_lock\_wait\_timeout = 50

\[mysqldump]  
quick  
max\_allowed\_packet = 16M

\[mysqladmin]  
#socket = /home/mysql/data/mysql.sock

\[mysql]  
no-auto-rehash  
\# Remove the next comment character if you are not familiar with SQL  
#safe-updates

\[myisamchk]  
key\_buffer\_size = 8M  
sort\_buffer\_size = 8M

\[mysqlhotcopy]  
interactive-timeout