源码包通常也采用tar.gz压缩,名称中只包含版本信息,大小也比RPM包、二进制包小很多,解压后的文件中含有INSTALL-SOURCE文件,可从MySQL官网(http://www.mysql.com/downloads/)下载,如:mysql-5.5.17.tar.gz
2. CMake
在采用源码包安装MySQL实例之前,先来介绍一下cmake这个编译工具。在MySQL 5.5之前,是采用configure工具执行源码编译的,到了MySQL 5.5,改用cmake进行编译。这是一个比make更高级的编译配置工具,可根据不同平台、不同编译器,生产相应的Makefile或者vcproj项目,所以需要首先从官网(http://www.cmake.org)下载cmake工具并安装之。
安装cmake之前安装gcc包
rpm -ivh kernel-headers-2.6.18-308.el5.x86_64.rpm
rpm -ivh glibc-headers-2.5-81.x86_64.rpm
rpm -ivh glibc-devel-2.5-81.x86_64.rpm
rpm -ivh gcc-4.1.2-52.el5.x86_64.rpm
rpm -ivh libstdc++-devel-4.1.2-52.el5.x86_64.rpm
rpm -ivh gcc-c++-4.1.2-52.el5.x86_64.rpm
安装cmake
cmake安装1:
安装cmake (MYSQL5.5是通过CMAKE进行编译的,所以需要先安装CMAKE)
#cd /usr/local/src
#tar xvf cmake-2.8.5.tar.gz
#cd cmake-2.8.5
#./configure
#make
#make install
/ mysql /cmake-2.8.3
./configure
gmake && make install
3. 安装mysql 5.5.17
3.1. 创建mysql系统组及用户
groupadd mysql
useradd -g mysql mysql
3.2. 设置用户操作系统资源限制
vi /etc/security/limits.conf
mysql soft nproc 2047
mysql hard nproc 16384
mysql soft nofile 1024
mysql hard nofile 65536
安装需要包
# rpm -ivh ncurses-devel-5.5-24.20060715.x86_64.rpm
# rpm -ivh bison-2.3-2.1.x86_64.rpm
3. 安装MYSQL Server
#mkdir /opt/mysql
#chown -R mysql:mysql /opt/mysql
#gunzip mysql-5.5.17.tar.gz
#tar xvf mysql-5.5.17.tar
#cd mysql-5.5.17
#cmake -DCMAKE_INSTALL_PREFIX=/application/mysql-5.5.32 \
-DMYSQL_USER=mysql \
-DMYSQL_TCP_PORT=3306 \
-DMYSQL_DATADIR=/application/mysql-5.5.32/data \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_READLINE=1 \
-DWITH_SSL=yes \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DEXTRA_CHARSETS=all
#make
#make install
注:有错误参考:
http://www.sijitao.net/1563.html
初始化DB
# sh scripts/mysql_install_db --user=mysql --basedir=/opt/mysql --datadir=/opt/mysql/data
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:
/opt/mysql/bin/mysqladmin -u root password 'new-password'
/opt/mysql/bin/mysqladmin -u root -h mysql password 'new-password'
Alternatively you can run:
/opt/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 /opt/mysql ; /opt/mysql/bin/mysqld_safe &
You can test the MySQL daemon with mysql-test-run.pl
cd /opt/mysql/mysql-test ; perl mysql-test-run.pl
Please report any problems with the /opt/mysql/scripts/mysqlbug script!
4. 启动Mysql Sever
配置service服务
[root@localhost init.d]# cp /application/mysql-5.5.32/support-files/mysql.server /etc/init.d/mysqld
[root@localhost init.d]# chmod +x /etc/init.d/mysqld
[root@localhost init.d]#
配置mysql参数文件my.cnf
[root@localhost support-files]# cp /application/mysql-5.5.32/support-files/my-small.cnf /etc/my.cnf
[root@localhost support-files]#
#vi /etc/my.cnf
[client]
#password = your_password
port = 3306
socket = /opt/mysql/data/mysql.sock
[mysqld]
port = 3306
server-id = 24
datadir = /opt/mysql/data
socket = /opt/mysql/data/mysql.sock
pid-file = /opt/mysql/data/mysql.pid
character-set-server = utf8
default_storage_engine = InnoDB
log-bin = /opt/mysql/data/mysql-bin
binlog_format = row
sync-binlog = 1
slow-query-log = on
slow-query-log-file = /opt/mysql/data/mysql-slow.log
log_error = /opt/mysql/data/mysql.err
max_connections = 2000
back_log = 50
skip-external-locking
skip-name-resolve
key_buffer_size = 256M
max_allowed_packet = 1M
table_open_cache = 2000
sort_buffer_size = 1M
read_buffer_size = 1M
read_rnd_buffer_size = 4M
myisam_sort_buffer_size = 64M
thread_cache_size = 8
query_cache_size = 16M
thread_concurrency = 8
innodb_data_home_dir = /opt/mysql/data
innodb_data_file_path = ibdata1:10M:autoextend
innodb_log_group_home_dir = /opt/mysql/data
innodb_buffer_pool_size = 256M
innodb_additional_mem_pool_size = 20M
innodb_log_file_size = 64M
innodb_log_buffer_size = 8M
innodb_flush_log_at_trx_commit = 1
innodb_lock_wait_timeout = 50
[mysqldump]
quick
max_allowed_packet = 16M
[mysql]
no-auto-rehash
#safe-updates
[myisamchk]
key_buffer_size = 128M
sort_buffer_size = 128M
read_buffer = 2M
write_buffer = 2M
[mysqlhotcopy]
interactive-timeout
"/etc/my.cnf" [New] 62L, 1531C written
[root@mysql support-files]# more /etc/my.cnf
[client]
#password = your_password
port = 3306
socket = /opt/data/mysql.sock
[mysqld]
port = 3306
server-id = 24
datadir = /opt/mysql/data
socket = /opt/mysql/data/mysql.sock
pid-file = /opt/mysql/data/mysql.pid
character-set-server = utf8
default_storage_engine = InnoDB
log-bin = /opt/mysql/data/mysql-bin
binlog_format = row
sync-binlog = 1
slow-query-log = on
slow-query-log-file = /opt/mysql/data/mysql-slow.log
log_error = /opt/mysql/data/mysql.err
max_connections = 2000
back_log = 50
skip-external-locking
skip-name-resolve
key_buffer_size = 256M
max_allowed_packet = 1M
table_open_cache = 2000
sort_buffer_size = 1M
read_buffer_size = 1M
read_rnd_buffer_size = 4M
myisam_sort_buffer_size = 64M
thread_cache_size = 8
query_cache_size = 16M
thread_concurrency = 8
innodb_data_home_dir = /opt/mysql/data
innodb_data_file_path = ibdata1:10M:autoextend
innodb_log_group_home_dir = /opt/mysql/data
innodb_buffer_pool_size = 256M
innodb_additional_mem_pool_size = 20M
innodb_log_file_size = 64M
innodb_log_buffer_size = 8M
innodb_flush_log_at_trx_commit = 1
innodb_lock_wait_timeout = 50
[mysqldump]
quick
max_allowed_packet = 16M
[mysql]
no-auto-rehash
#safe-updates
[myisamchk]
key_buffer_size = 128M
sort_buffer_size = 128M
read_buffer = 2M
write_buffer = 2M
[mysqlhotcopy]
interactive-timeout
# service mysql start
Starting MySQL....[ OK ]
或者:
[root@localhost support-files]# /etc/init.d/mysqld start
Starting MySQL... [ OK ]
[root@localhost support-files]# service mysqld stop
Shutting down MySQL. [ OK ]
[root@localhost support-files]# service mysqld start
Starting MySQL.. [ OK ]
[root@localhost support-files]#
下面我们登录mysql数据库看下,要使用mysql命令。我们需要把/application/mysql-5.5.32/bin路径加入到系统的环境变量中,否则mysql命令无法使用。如下:
[root@localhost mysql-5.5.32]#
[root@localhost mysql-5.5.32]# echo $PATH
/usr/lib/qt-3.3/bin:/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
[root@localhost mysql-5.5.32]# echo PATH=$PATH:/application/mysql-5.5.32/bin/ >> /etc/profile
[root@localhost mysql-5.5.32]# source /etc/profile
[root@localhost mysql-5.5.32]#
[root@localhost mysql-5.5.32]#
[root@localhost mysql-5.5.32]# echo $PATH
/usr/lib/qt-3.3/bin:/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/application/mysql-5.5.32/bin/