安装前工作
1、下载源码
下载mysql、boost压缩包
wget https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.28.tar.gz
wget https://gigenet.dl.sourceforge.net/project/boost/boost/1.59.0/boost_1_59_0.tar.gz
2、安装依赖
yum -y install cmake ncurses-devel gcc gcc-c++ pcre pcre-devel openssl openssl-devel
3、解压
tar -zxvf mysql-5.7.28.tar.gz -C /opt
tar -zxvf boost_1_59_0.tar.gz -C /opt
4、编译安装mysql
cd /opt/mysql-5.7.28
cmake -DCMAKE_INSTALL_PREFIX=/data/mysql \
-DWITH_BOOST=/opt/boost_1_59_0 \
-DMYSQL_UNIX_ADDR=/data/mysql/tmp/mysql.sock \
-DMYSQL_DATADIR=/data/mysql/data \
-DDEFAULT_CHARSET=utf8mb4 \
-DDEFAULT_COLLATION=utf8mb4_general_ci \
-DWITH_EXTRA_CHARSETS=all \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DWITH_INNODB_MEMCACHED=1 \
-DWITH_DEBUG=OFF \
-DWITH_ZLIB=bundled \
-DENABLED_LOCAL_INFILE=1 \
-DENABLED_PROFILING=ON \
-DMYSQL_MAINTAINER_MODE=OFF \
-DMYSQL_TCP_PORT=3306
5、配置
配置环境变量
vim /etc/profile
export PATH=/data/mysql/bin:$PATH
export PATH=/data/mysql/bin:/data/mysql/lib:$PATH
source /etc/profile
6、创建mysql用户和data目录
cd /data/mysql
mkdir -p /data/mysql/{tmp,logs,pids,share,data}
touch /data/mysql/logs/mysqld.log
touch /data/mysql/pids/mysqld.pid
useradd -s /sbin/nologin -M mysql
chown -R mysql:mysql /data/mysql
7、修改my.cnf配置文件
[mysqld]
[mysqld_safe]
[client]
8、假如守护进程
cd /opt/mysql-5.7.28
cp support-files/mysql.server /etc/init.d/mysql
chmod a+x /etc/init.d/mysql
chkconfig --add mysql
chkconfig mysql on
9、初始化数据库
mysqld --initialize-insecure --user=mysql --basedir=/data/mysql --datadir=/data/mysql/data
10、启动mysql
service mysql start
11、登录mysql ,修改密码
mysql -u root -p #第一次登陆不需要密码,回车即可
set password for root@localhost = password('123456'); #修改密码
flush privileges;
搭建完成