[root@db02 ~]# wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.35.tar.gz
[root@db02 ~]# tar xf mysql-5.7.35.tar.gz
[root@db02 ~]# cd mysql-5.7.35/
#安装依赖
[root@db02 ~/mysql-5.7.35]# yum install -y ncurses-devel libaio-devel gcc gcc-c++ glibc cmake autoconf openssl openssl-devel
#安装boots 一组C++ 库的集合,提供了线性代数、伪随机数生成、多线程、图像处理、正则表达式、单元测试等功能。
[root@db02 ~/mysql-5.7.35]# wget http://sourceforge.net/projects/boost/files/boost/1.59.0/boost_1_59_0.tar.gz
[root@db02 ~/mysql-5.7.35]# tar xf boost_1_59_0.tar.gz -C /usr/local
#cmake一下
[root@db02 ~/mysql-5.7.35]# cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql-5.7.35 \
-DMYSQL_DATADIR=/usr/local/mysql-5.7.35/data \
-DMYSQL_UNIX_ADDR=/usr/local/mysql-5.7.35/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
[root@db02 ~/mysql-5.7.35]# make
[root@db02 ~/mysql-5.7.35]# make install
#创建数据存放目录
[root@db02 ~/mysql-5.7.35]# cd /usr/local
[root@db02 /usr/local]# ln -s /usr/local/mysql-5.7.35 /usr/local/mysql
[root@db02 /usr/local]# mkdir /usr/local/mysql-5.7.35/{data,tmp}
[root@db02 /usr/local]# touch /var/log/mysqld.log
[root@db02 /usr/local]# chown -R mysql.mysql /usr/local/mysql-5.7.35
[root@db02 /usr/local]# chown -R mysql.mysql /var/log/mysqld.log
#初始化 注:初始化时,data目录必须为空
[root@db02 /usr/local]# /usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
#参数介绍:
--initialize-insecure 不安全初始化,即没有密码。
--initialize 安全初始化,会自动生成临时密码。在log-error里,查询 temporary password
--user=mysql 初始化用户
--basedir=/service/mysql 软件安装目录
--datadir=/service/mysql/data 数据存放位置
#编辑配置文件
[root@db02 /usr/local]# 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
#加入systemd管理
[root@db02 /usr/local]# cp mysql/support-files/mysql.server /etc/init.d/mysqld
[root@db02 /usr/local]# 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
[root@db02 /usr/local]# systemctl daemon-reload
[root@db02 /usr/local]# systemctl start mysqld
#查询默认初始密码
[root@db02 /usr/local]# grep 'temporary password' /var/log/mysqld.log
2021-09-24T01:38:06.444154Z 1 [Note] A temporary password is generated for root@localhost: z8oqda0;f,pJ
#测试连接
[root@db02 /usr/local]# /usr/local/mysql/bin/mysql -uroot -p'v><y4(H&BuSu'
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.35
Copyright (c) 2000, 2021, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
#设置环境变量
[root@db02 /usr/local]# vim /etc/profile.d/mysql.sh
export PATH=/usr/local/mysql/bin:$PATH
[root@db02 /usr/local]# source /etc/profile
#使用mysql命令连接
[root@db02 /usr/local]# mysql -uroot -p'v><y4(H&BuSu'
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.7.35
Copyright (c) 2000, 2021, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
#修改密码
mysql> alter user root@localhost identified by 'boy@123';
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;