CentOS下MySQL源码安装
卸载系统自带的MySQL
yum remove mysql mysql-server mysql-libs compat-mysql51
rm -rf /var/lib/mysql rm /etc/my.cnf
rpm -qa|grep mysql
|
MySQL源码安装
MySQL下载
下载地址,选择最下面“Generic Linux”版本
http://dev.mysql.com/downloads/mysql/5.6.html#downloads
解压编译,安装工具包
tar xvf mysql-5.6.30.tar.gz cd mysql-5.6.30 yum -y install make gcc gcc-c++ cmake bison-devel ncurses-devel libaio bison libaio libaio-devel perl-Data-Dumper net-tools
|
编译,注意cmake \后面操作都带有“-”符号
cmake \ -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \ -DMYSQL_DATADIR=/usr/local/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=/var/lib/mysql/mysql.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
|
编译成功,执行安装
MySQL5.7版本需增加“-DDOWNLOAD_BOOST=1 -DWITH_BOOST=/usr/local/boost”
如果编译出现问题,执行“rm CMakeCache.txt”,便可重新编译
创建用户
groupadd mysql useradd -g mysql mysql
chown -R mysql:mysql /usr/local/mysql
ln -s /usr/local/mysql/bin/mysql /usr/bin
|
有时候执行service mysql start命令报错env: /etc/init.d/mysql:权限不够问题
解决办法:执行下面的语句
chmod a+wrx /etc/init.d/mysql
实例安装
进入安装包的路径
执行脚本
scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql
|
#####5.7以后版本,执行脚本方法变动如下
/usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
|
/usr/local/mysql/my.cnf 为my.cnf默认路径
添加端口到防火墙
firewall-cmd --zone=public --add-port=3306/tcp --permanent firewall-cmd --reload
|
添加服务,拷贝服务脚本到init.d目录,并设置开机启动
cp support-files/mysql.server /etc/init.d/mysql chkconfig mysql on
|
启动MySQL