上一节我们讲了编译安装及配置Nginx https://www.server7.cc/2024/08/11/121.html
一、安装扩展
dnf -y install gcc gcc-c++ ncurses ncurses-devel cmake
二、编译
#不带boost编译安装
wget https://cdn.mysql.com/archives/mysql-5.7/mysql-5.7.34.tar.gz
wget http://downloads.sourceforge.net/project/boost/boost/1.59.0/boost_1_59_0.tar.gz
#安装boost
tar xzf boost_1_59_0.tar.gz
cd boost_1_59_0
./bootstrap.sh
./b2 install
#创建mysql用户
groupadd mysql
useradd -r -g mysql -s /bin/false mysql
#预编译安装
cd mysql-5.7.34
cmake -DCMAKE_INSTALL_PREFIX=/www/mysql -DMYSQL_UNIX_ADDR=/www/mysql/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS=all -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DENABLED_LOCAL_INFILE=1 -DMYSQL_DATADIR=/www/mysql/data -DMYSQL-USER=mysql -DDOWNLOAD_BOOST=1 -DWITH_BOOST=/usr/local/boost
此处会出现两处错误依体统决定 出现错误我们需要安装扩展 扩展找不到安装方法 去链接上上面搜:https://pkgs.org/
选择系统执行命令即可安装 (包括后续php安装也是一样,少了什么扩展安装什么扩展)
make
make install
vi /www/mysql/conf/my.cnf
[mysqld_safe]
log-error=/www/mysql/log/error.log
[mysqldump]
quick
[mysql]
no-auto-rehashsocket=/tmp/mysql.sock
[client]
default-character-set=utf8mb4
[mysqld]
basedir=/www/mysql
socket=/tmp/mysql.sock
tmpdir=/tmpdata
dir=/www/mysql/data
default_authentication_plugin=mysql_native_password
character-set-server=utf8mb4
port=3306
user=mysql
pid-file=/www/mysql/mysqld.pid
配置MySQL加入systemctl管理服务 创建mysqld.service文件
vim /usr/lib/systemd/system/mysqld.service
[Unit]
Description=MySQL
ServerDocumentation=man:mysqld
Documentation=http://dev/mysql.com/doc/refman/en/using-systemd.html
After=network.target
[Service]
User=mysql
Group=mysql
ExecStart=/www/mysql/bin/mysqld –defaults- file=/www/mysql/conf/my.cnf
LimitNOFILE=65536
LimitNPROC=65536
[Install]
WantedBy=multi-user.target
#添加启动项
cp /wwwmysql/support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
chkconfig –add mysqld
chkconfig mysqld on
#初始化数据库
/www/mysql/bin/mysqld –initialize-insecure –user=mysql –basedir=/usr/local/mysql –datadir=/data/mysql
初始化之后需要做软链接:
ln -s /tmp/mysql.sock /www/mysql/mysql.sock
# 启动数据库
systemctl start mysqld
#获取临时密码
cat /www/mysql.err|grep pass|awk ‘{print $NF}’
登陆执行修改密码
提示:如果初始化一次不行,可以重复初始化,需要 rm -rf /www/mysql/data/*
到这里我们的mysql就已经编译并配置完成了 下一章我们讲如何编译配置php7.4