#基础环境
yum -y install make gcc-c++ cmake bison-devel ncurses-devel
#添加用户
groupadd mysql
useradd -r -g mysql mysql
#下载源码包
wget http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.16.tar.gz
#解压
tar zxvf mysql-5.6.16.tar.gz && cd mysql-5.6.16
##cmake编译:
cmake \
-DCMAKE_INSTALL_PREFIX=/opt/mysql \
-DMYSQL_DATADIR=/opt/mysql/data \
-DSYSCONFDIR=/etc \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DMYSQL_UNIX_ADDR=/tmp/mysql3306.sock \
-DMYSQL_TCP_PORT=3306 \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DEXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci
状态:
CMake Warning (dev) in sql/CMakeLists.txt:
Policy CMP0022 is not set: INTERFACE_LINK_LIBRARIES defines the link
interface. Run "cmake --help-policy CMP0022" for policy details. Use the
cmake_policy command to set the policy and suppress this warning.
Target "mysqld" has an INTERFACE_LINK_LIBRARIES property which differs from
its LINK_INTERFACE_LIBRARIES properties.
INTERFACE_LINK_LIBRARIES:
-lpthread;sql;binlog;rpl;master;slave;sql;mysys;mysys_ssl
LINK_INTERFACE_LIBRARIES:
rt
This warning is for project developers. Use -Wno-dev to suppress it.
-- Generating done
CMake Warning:
Manually-specified variables were not used by the project:
WITH_MEMORY_STORAGE_ENGINE
WITH_READLINE
-- Build files have been written to: /root/mysql-5.6.16
注意::这个cmake是替代以前的./configure 步骤。如果你需要更多的参数,请参考http://dev.mysql.com/doc/refman/5.6/en/source-configuration-options.html。
make && make install
安装数据库
cd /opt/mysql/scripts
./mysql_install_db --user=mysql --basedir=/opt/mysql --datadir=/opt/mysql/data
注册为服务
cd /opt/mysql/support-files
###############注册服务
cp mysql.server /etc/rc.d/init.d/mysql
#使用默认配置文件
cp my-default.cnf /etc/my.cnf
#让chkconfig管理mysql服务
chkconfig --add mysql
#开机启动
chkconfig mysql on
赋予数据存放目录权限
# chown mysql:mysql –R /opt/mysql/data
############启动MySQL服务
service mysql start
################改变编码,防止乱码
SHOW VARIABLES LIKE ‘character%‘
修改mysql的my.cnf文件
[client]
default-character-set=utf8
[mysqld]
character-set-server=utf8
[mysql]
default-character-set=utf8
#############将mysql的bin加入到path中
cd ~
#我把path添加到当前用户目录的bashrc中,如果需要全局设定,请修改`/etc/profile`
vi .bashrc
#加入以下内容
PATH=/usr/local/mysql/bin:$PATH
export PATH
软连接到/usr/bin
ln -s /opt/mysql/bin/mysql /usr/bin/
配置用户密码和远程访问权限
mysql -uroot
use mysql
SET PASSWORD = PASSWORD(‘123456‘);
GRANT ALL PRIVILEGES ON *.* TO ‘root‘@‘%‘ IDENTIFIED BY ‘123456‘ WITH GRANT OPTION;