1、安装源码安装需要的环境以及下载源码包
yum -y groupinstall “Development Tools”
yum -y install ncurses ncurses-devel bison libgcrypt perl make cmake
wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-boost-5.7.24.tar.gz
2、创建mysql运行所需要的用户,组以及存储目录等
groupadd mysql
useradd mysql -M -g mysql -s /sbin/nologin
mkdir -p /usr/local/mysqld/{data,mysql,log,tmp}
chown mysql:mysql -R /usr/local/mysqld/*
3、解压mysql的源码包 并且预编译
cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysqld/mysql
-DMYSQL_DATADIR=/usr/local/mysqld/data
-DWITH_BOOST=./boost
-DDEFAULT_CHARSET=utf8
4、编译安装
make
make install
安装到此结束,下面开始初始化mysql进行安装配置
1、将mysql命令提升为系统级别的,不提升只能在安装目录下面使用
vim /etc/profile.d/mysql.sh
export PATH=$PATH:/usr/local/mysqld/mysql/bin
保存退出
source /etc/profile.d/mysql.sh (重新加载环境变量)
echo $PATH (验证环境变量是否配置成功 查看PATH路径)
2、复制安装位置的配置文件到/etc下面
chown -R mysql:mysql /usr/local/mysqld/*
cp /usr/local/mysqld/mysql/mysql-test/include/default_mysqld.cnf /etc/my.cnf
3、配置my.cnf文件
[mysqld]
basedir = /usr/local/mysqld/mysql
datadir = /usr/local/mysqld/data
tmpdir = /usr/local/mysqld/tmp
socket = /usr/local/mysqld/tmp/mysql.sock
pid_file = /usr/local/mysqld/tmp/mysqld.pid
log_error = /usr/local/mysqld/log/mysql_error.log
slow_query_log_file = /usr/local/mysqld/log/slow_warn.log
server_id = 11
user = mysql
port = 3306
bind-address = 0.0.0.0
character-set-server = utf8
default_storage_engine = InnoDB
4、初始化数据库服务操作
mysqld --defaults-file=/etc/my.cnf --initialize --user=‘mysql’
5、启动数据库
mysqld_safe --defaults-file=/etc/my.cnf
6、设置mysql.socket 软连接到mysql命令指定的目录中 不设置这个 mysql启动以后无法登录到数据库中
ln -s /usr/local/mysqld/tmp/mysql.sock /tmp/mysql.sock
7、截取mysql初始密码
grep password /var/log/mysqld.log
8、用截取到密码登录到数据库,按照yum安装后面数据库操作步,参考上一片文章yum安装配置。如果遇到截取不到密码,按照不知道密码操作来