一、系统环境:
# cat /etc/redhat-release
CentOS release 6.9 (Final)
二、mysql 编译安装:
1、安装依赖包:
yum install -y ncurses-devel libaio-devel cmake
2、创建mysql管理用户:
useradd -s /sbin/nologin -M mysql
id mysql
3、下载mysql软件包,解压、配置、编译、安装:
cd mysql-5.6.38
cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql-5.6.38 -DMYSQL_DATADIR=/usr/local/mysql-5.6.38/data -DMYSQL_UNIX_ADDR=/usr/local/mysql-5.6.38/tmp/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS=all -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_FEDERATED_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 -DWITH_ZLIB=bundled -DWITH_SSL=bundled -DENABLED_LOCAL_INFILE=1 -DWITH_EMBEDDED_SERVER=1 -DENABLE_DOWNLOADS=1 -DWITH_DEBUG=0
make && make install
ln -s /usr/local/mysql-5.6.38/ /usr/local/mysql
三、数据库安装成功配置:
1、复制模板配置文件:
\cp /usr/local/mysql/support-files/my-large.cnf /etc/my.cnf
2、初始化数据库:
/usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data --user=mysql
防止报错:数据库启动会提示,找不到xx/tmp/mysql.sock,原因是5.6.38版本不会自动创建tmp目录,需要我们手工创建。
mkdir /usr/local/mysql/tmp
3、修改mysql目录的属主,属组
chown -R mysql.mysql /usr/local/mysql/
4、复制启动脚本,并修改权限:
cp support-files/mysql.server /etc/init.d/mysqld
chmod 700 /etc/init.d/mysqld
5、配置环境变量,使用mysql命令
echo ‘PATH=/usr/local/mysql/bin/:$PATH‘ >>/etc/profile
tail -1 /etc/profile
source /etc/profile
echo $PATH
mysql
6、数据库安全配置,设置root用户密码:
mysqladmin -u root password ‘123456‘
mysql -uroot -p123456
MySQL 5.6.38 编译安装完成!