mysql-5.5.x的编译和安装

从mysql-5.5开始,mysql源码安装开始使用cmake。编译安装和以前的版本有些不同。如果要使用源码编译安装mysql5.5.x,首先需要安装cmake。

cmake的编译和安装

从 http://www.cmake.org/cmake/resources/software.html 下载最新版本的cmake。

yum install bison
wget http://www.cmake.org/files/v2.8/cmake-2.8.5.tar.gz
tar zxvf cmake-2.8.5.tar.gz
cd cmake-2.8.5
./bootstrap 
make
make install

mysql-5.5.x的编译安装

从 http://dev.mysql.com/get/Downloads/MySQL-5.5/mysql-5.5.14.tar.gz/from/http://mysql.he.net/ 下载mysql源码。

创建mysql用户和组

/usr/sbin/groupadd mysql
/usr/sbin/useradd -g mysql mysql

编译安装

tar zxvf mysql-5.5.14.tar.gz
cd mysql-5.5.14

cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DEXTRA_CHARSETS=all \
-DWITH_READLINE=1 \
-DWITH_SSL=system \
-DWITH_EMBEDDED_SERVER=1 \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITHOUT_PARTITION_STORAGE_ENGINE=1 \
-DWITH_DEBUG=0

make && make install

MySQL 5.6.x 编译参数:

cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DEXTRA_CHARSETS=all \
-DWITH_SSL=bundled \
-DWITH_EMBEDDED_SERVER=1 \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_DEBUG=0 \
-DENABLE_DOWNLOADS=1

如果需要更改配置:

make clean
rm -f CMakeCache.txt

复制配置文件

cp support-files/my-medium.cnf /usr/local/mysql/my.cnf

设置权限

chmod +w /usr/local/mysql
chown -R mysql:mysql /usr/local/mysql

配置开机自动启动

cp support-files/mysql.server /etc/init.d/mysql
chmod +x /etc/init.d/mysql
/sbin/chkconfig --add mysql
/sbin/chkconfig mysql on

修改my.cnf配置
[mysqld]添加

datadir=/usr/local/mysql/data
default-storage-engine=MyISAM
#MYSQL 5.6.x 添加 default-tmp-storage-engine=MyISAM
loose-skip-innodb
thread_concurrency = 2

thread_concurrency 为 CPU 数×2。

安装默认数据表

/usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql \
--datadir=/usr/local/mysql/data \
--user=mysql

启动mysql

/usr/local/mysql/bin/mysqld_safe --defaults-file=/usr/local/mysql/my.cnf &

最后的&表示在后台运行

或者使用 service mysql start 启动。

注:mysql启动错误记录中出现 InnoDB: Error: pthread_create returned 12 错误解决办法:

1.如果只使用MyISAM引擎,不需要使用InnoDB,则尝试在配置文件my.cnf中添加 explicit_defaults_for_timestamp=true 和 default-tmp-storage-engine=MYISAM 和 default-storage-engine=MyISAM 和 loose-skip-innodb,禁用InnoDB,并且删除skip-bdb。和旧版本配置中不同的是,旧版本配置中的 skip-locking 改为 skip-external-locking,skip-innodb 改为 loose-skip-innodb,skip-bdb 在新版本中已经删除。

MySQL5.6.X 禁用InnoDB引擎,只使用MyISAM引擎my.cnf配置参数

explicit_defaults_for_timestamp=true
default-storage-engine=MyISAM
default-tmp-storage-engine=MYISAM
skip-external-locking
loose-skip-innodb
loose-innodb-trx=0
loose-innodb-locks-unsafe-for-binlog=0
loose-innodb-lock-waits=0
loose-innodb-cmp-per-index-enabled=0
loose-innodb-cmp-per-index-reset=0
loose-innodb-cmp-reset=0
loose-innodb-cmpmem=0
loose-innodb-cmpmem-reset=0
loose-innodb-buffer-page=0
loose-innodb-buffer-page-lru=0
loose-innodb-buffer-pool-stats=0
loose-innodb-metrics=0
loose-innodb-ft-default-stopword=0
loose-innodb-ft-deleted=0
loose-innodb-ft-being-deleted=0
loose-innodb-ft-config=0
loose-innodb-ft-index-cache=0
loose-innodb-ft-index-table=0
loose-innodb-sys-tables=0
loose-innodb-sys-tablestats=0
loose-innodb-sys-indexes=0
loose-innodb-sys-columns=0
loose-innodb-sys-fields=0
loose-innodb-sys-foreign=0
loose-innodb-sys-foreign-cols=0

2.如果要使用InnoDB引擎,则删除loose-skip-innodb,default-storage-engine=MyISAM,并取消my.cnf中关于InnoDB相关设置的注释,例如:

# Uncomment the following if you are using InnoDB tables
innodb_data_home_dir = /usr/local/mysql/data
innodb_data_file_path = ibdata1:10M:autoextend
innodb_log_group_home_dir = /usr/local/mysql/data
# 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

使用以下命令测试mysql

/usr/local/mysql/bin/mysqladmin version
/usr/local/mysql/bin/mysqladmin variables

安装的mysql的root密码一般都是空,执行下面命令设置密码:

/usr/local/mysql/bin/mysql -u root
SET PASSWORD FOR 'root'@'localhost' =PASSWORD('your new password');
flush privileges;

重置mysql的root密码
1. Stop the MySQL service.

service mysql stop

2. Start MySQL without password and permission checks.

/usr/local/mysql/bin/mysqld_safe --skip-grant-tables &

3. Press [ENTER] again if your output is halted.

4. Connect to MySQL.

/usr/local/mysql/bin/mysql -u root mysql

5. Run following commands to set a new password for root user. Substitute NEW_PASSWORD with your new password.

    UPDATE user SET password=PASSWORD('NEW_PASSWORD') WHERE user='root';
    FLUSH PRIVILEGES;
    

6. Restart the MySQL service.

service mysql restart

参考资料:
有关CMake的参数选项的说明,请查阅:
http://forge.mysql.com/wiki/CMake
http://forge.mysql.com/wiki/Autotools_to_CMake_Transition_Guide
http://forge.mysql.com/wiki/MySQL_Internals_Support_for_Plug-Ins

7月 20, 2011 | In: 数据库

Comment Form

You must be logged in to post a comment.

分类

归档

ipv6 ready