起因:
CentOS内置源里面默认安装的Mysql-server太老旧,不支持一些新方法的调用,需要重新安装一个新版本
老版本里面有数据,不想卸载,想保留库和软件本身
机器上没有运行Docker,而且数据库不太适合Docker化
看来编译安装最适合
目标:
编译安装Mysql-server5.6.32
并保留mysql-server-5.1.73-7.el6.x86_64
准备工作:
备份原始配置文件
(备份rpm包安装的Mysql-server的配置文件)
cp /etc/my.cnf /etc/my.cnf.bak
下载软件包
wget http://downloads.mysql.com/archives/get/file/mysql-5.6.32.tar.gz
tar -zxvf mysql-5.6.32.tar.gz
具体步骤
切换到Mysql-server目录准备编译源码
cd mysql-5.6.32
运行下面cmake指令,提示缺少libncurses5-dev
yum install libncurses5-dev
失败,因为libncurses5-dev是debian下面的包名字,而CentOS下面应该运行
yum install ncurses-devel
再次运行编译
cmake
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql
-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock
-DDEFAULT_CHARSET=utf8
-DDEFAULT_COLLATION=utf8_general_ci
-DWITH_INNOBASE_STORAGE_ENGINE=1
-DWITH_ARCHIVE_STORAGE_ENGINE=1
-DWITH_BLACKHOLE_STORAGE_ENGINE=1
-DMYSQL_DATADIR=/home/mysqldata
-DMYSQL_TCP_PORT=3306
-DENABLE_DOWNLOADS=1
------------------------
注意:若要重新运行配置,需要删除目录内CMakeCache.txt文件
rm CMakeCache.txt
------------------------
make && make install
使用下面的命令查看是否有mysql用户及用户组
(由于我这个机器上原来有rpm包安装的Mysql所有就忽律查看或者添加用户组的步骤啦!)
cat /etc/passwd 查看用户列表
cat /etc/group 查看用户组列表
如果没有就创建
groupadd mysql
useradd -g mysql mysql
修改/usr/local/mysql权限
chown -R mysql:mysql /usr/local/mysql
修改配置文件
cp support-files/my-default.cnf /etc/my.cnf
vi /etc/my.cnf
-----my.cnf begin------
[client]
default-character-set=utf8
socket = /usr/local/mysql/mysql.sock
[mysql]
default-character-set=utf8
[mysqld]
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
# These are commonly set, remove the # and set as required.
basedir = /usr/local/mysql
datadir = /home/mysqldata/
port = 3306
# server_id = .....
socket = /usr/local/mysql/mysql.sock
character-set-server=utf8
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
-----my.cnf end------
初始化数据库
cd /usr/local/mysql/
./scripts/mysql_install_db --user=mysql --datadir=/home/mysqldata
修改文件和目录权限,否则开启服务会报错
chown -R mysql:root /usr/local/mysql/mysql.sock
chown -R mysql:root /usr/local/mysql
测试开启编译安装的Mysql
/usr/local/mysql/bin/mysqld_safe
运行正常则添加启动脚本
cp support-files/mysql.server /etc/init.d/mysql
chkconfig mysql on
service mysql start --启动MySQL
--------------
注意,因为我这里有原来rpm包安装的Mysql-server,
所以为了不覆盖其启动脚本
cp support-files/mysql.server /etc/init.d/mysql_tarball
chkconfig mysql_tarball on
service mysql_tarball start --启动MySQL
--------------