1.下载源码包、解压
wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.35.tar.gz
tar xf mysql-5.7.35.tar.gz
cd mysql-5.7.35/
2.安装依赖
yum install -y ncurses-devel libaio-devel gcc gcc-c++ glibc cmake autoconf openssl openssl-devel
3.#安装boots 一组C++ 库的集合,提供了线性代数、伪随机数生成、多线程、图像处理、正则表达式、单元测试等功能
wget http://sourceforge.net/projects/boost/files/boost/1.59.0/boost_1_59_0.tar.gz
tar xf boost_1_59_0.tar.gz -C /usr/local
4.cmake
cd mysql-5.7.35/
cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql-5.7.44 -DMYSQL_DATADIR=/usr/local/mysql-5.7.44/data -DMYSQL_UNIX_ADDR=/usr/local/mysql-5.7.44/tmp/mysql.sock -DDOWNLOAD_BOOST=1 -DWITH_BOOST=/usr/local/boost_1_59_0 -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=system -DENABLED_LOCAL_INFILE=1 -DWITH_EMBEDDED_SERVER=1 -DENABLE_DOWNLOADS=1 -DWITH_DEBUG=0
5.编译
make && make install
6.创建数据存放目录
cd /usr/local
ln -s /usr/local/mysql-5.7.35 /usr/local/mysql
mkdir /usr/local/mysql-5.7.35/{data,tmp}
touch /var/log/mysqld.log
useradd -s /sbin/nologin mysql
chown -R mysql.mysql /usr/local/mysql-5.7.35
chown -R mysql.mysql /var/log/mysqld.log
7.初始化数据库 #会得到root初始密码
/usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
8.编辑配置文件
vim /etc/my.cnf
[mysqld]
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
port=3306
socket=/usr/local/mysql/tmp/mysql.sock
character-set-server=utf8mb4
log-error=/var/log/mysqld.log
pid-file=/usr/local/mysql/tmp/mysqld.pid
[mysql]
socket=/usr/local/mysql/tmp/mysql.sock
[client]
socket=/usr/local/mysql/tmp/mysql.sock
9.加入systemctl管理
cp mysql/support-files/mysql.server /etc/init.d/mysqld
vim /usr/lib/systemd/system/mysqld.service
[Unit]
Description=MySQL Server
Documentation=man:mysqld(8)
Documentation=https://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target After=syslog.target
[Install]
WantedBy=multi-user.target
[Service]
User=mysql
Group=mysql
ExecStart=/usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf
LimitNOFILE = 5000
systemctl daemon-reload
systemctl start mysqld
10.测试连接 修改默认密码、刷新权限 #密码在第7步
/usr/local/mysql/bin/mysql -uroot -p'v><y4(H&BuSu'
alter user root@localhost identified by 'passwd';
flush privileges;
11.加入环境变量
vim /etc/profile.d/mysql.sh
export PATH=/usr/local/mysql/bin:$PATH
source /etc/profile