Mysql的源码安装

本次主要记录Linux下Mysql-5.5.23的源码安装记录文档。

安装环境:
操作系统:CentOS 6.2
数据库:MYSQL 5.5.23
虚拟机:VMWARE 8.0.2

步骤主要有:
1.下载mysql源码安装包
地址:http://www.mysql.com/downloads/mysql/#downloads,选择的platform为source code,我这次选的是5.5.23版本

2.环境的配置

下载到服务器上后,会发现与之前版本的安装有所区别,之前是使用的./configure来配置的,但是本次下载的版本已经没有了,但是多了几个cmake文件,查看相关文档得知,已经取代了之前的configure检查安装。所以环境中需要安装cmake包,当然gcc等关键安装包是必须的。
本次下载的cmake版本是cmake-2.8.3.tar.gz。
cmake的安装:
#tar xvf cmake-2.8.3.tar.gz
#cd cmake-2.8.3
#./bootstrap
#gmake
#gmake install

或者yum install -y cmake

3.用户配置
#groupadd mysql
#useradd mysql -g mysql

4.mysql的安装(root下)
# tar xvf mysql-5.5.23.tar.gz
# cd mysql-5.5.23
# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS:STRING=utf8,gbk -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DENABLED_LOCAL_INFILE=1 -DMYSQL_DATADIR=/usr/local/mysql -DMYSQL_USER=mysql -DMYSQL_TCP_PORT=3306

过程如下:
-- MySQL 5.5.23
-- Packaging as: mysql-5.5.23-Linux-x86_64
-- Configuring done
-- Generating done
-- Build files have been written to: /home/mysql/mysql-5.5.23
敲cmake命令时将上述命令弄成一行回车。
编译及安装等
# make
# make install
# cd support-files/
# cp my-large.cnf /etc/my.cnf
# cp mysql.server /etc/init.d/mysqld
初始化DB
# /usr/local/mysql/scripts/mysql_install_db --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql --datadir=/usr/local/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:

/usr/local/mysql/bin/mysqladmin -u root password 'new-password'
/usr/local/mysql/bin/mysqladmin -u root -h localhost.localdomain password 'new-password'

Alternatively you can run:
/usr/local/mysql/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 /usr/local/mysql ; /usr/local/mysql/bin/mysqld_safe &

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

Please report any problems with the /usr/local/mysql/scripts/mysqlbug script!

5.配置my.cnf
修改/etc/my.cnf文件,新增如下内容:
#added by kenyon 20120418 about the log para
[client]
#password       = your_password
port            = 3306
socket          = /tmp/mysql.sock

# The MySQL server
[mysqld]
port            = 3306
socket          = /tmp/mysql.sock

log-bin=/usr/local/mysql/log/mysql-bin
# expire_logs_days = 30
# max_binlog_size = 500M
log=/usr/local/mysql/log/mysql.log
log-error=/usr/local/mysql/log/error.log
long_query_time=2
log-slow-queries=/usr/local/mysql/log/slowquery.log
# log-queries-not-using-indexes=/usr/local/mysql/log/nouseindex.log

[mysqld_safe]
datadir=/usr/local/mysql/data/

6.授权
# chown -R mysql /usr/local/mysql/data
# mkdir /usr/local/mysql/log
# chown -R mysql /usr/local/mysql/log

7.启动与关闭
启动:
/usr/local/mysql/bin/mysqld_safe &
[mysql@localhost log]$ mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.5.23-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> select version();
+------------+
| version()  |
+------------+
| 5.5.23-log |
+------------+
1 row in set (0.00 sec)

 

在/etc/init.d/mysqld新增
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data

完了,该文件除了启动和关闭也可以有其他用处
启动:/etc/init.d/mysqld start
关闭:/etc/init.d/mysqld stop
重载:/etc/init.d/mysqld reload/force-reload
状态:/etc/init.d/mysqld status

你可能感兴趣的:(mysql,源码安装)