//创建用户和组
[root@localhost ~]# useradd -r -M -s /sbin/nologin mysql//安装依赖包
[root@localhost ~]# yum -y install ncurses-devel openssl-devel openssl cmake mariadb-devel ncurses-compat-libs//下载二进制格式的mysql软件包
[root@localhost ~]# cd /usr/src/[root@localhost src]# wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.34-linux-glibc2.12-x86_64.tar.gz[root@localhost src]# ls mysql*
mysql-5.7.34-linux-glibc2.12-x86_64.tar.gz
//解压
[root@localhost src]# tar xf mysql-5.7.34-linux-glibc2.12-x86_64.tar.gz -C /usr/local/[root@localhost src]# ls /usr/local/mysql-5.7.34-linux-glibc2.12-x86_64/bin docs include lib LICENSE man README share support-files
//创建软连接
[root@localhost src]# cd /usr/local/[root@localhost local]# ln -sv mysql-5.7.34-linux-glibc2.12-x86_64/ mysql'mysql'->'mysql-5.7.34-linux-glibc2.12-x86_64/'[root@localhost local]# ll mysql
lrwxrwxrwx.1 root root 3610月 2702:44 mysql -> mysql-5.7.34-linux-glibc2.12-x86_64///修改属主属组
[root@localhost ~]# chown -R mysql.mysql /usr/local/mysql[root@localhost local]# ll mysql
lrwxrwxrwx.1 mysql mysql 3610月 2702:44 mysql -> mysql-5.7.34-linux-glibc2.12-x86_64///添加环境变量
[root@localhost ~]# ls /usr/local/mysqlbin docs include lib LICENSE man README share support-files
[root@localhost ~]# echo 'export PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh[root@localhost ~]# source /etc/profile.d/mysql.sh[root@localhost ~]# which mysql/usr/local/mysql/bin/mysql
//头文件(include)、读取lib
[root@localhost ~]# ln -sv /usr/local/mysql/include/ /usr/local/include/mysql'/usr/local/include/mysql'->'/usr/local/mysql/include/'[root@localhost ~]# echo '/usr/local/mysql/lib' > /etc/ld.so.conf.d/mysql.conf[root@localhost ~]# ldconfig//创建数据存放目录
[root@localhost ~]# mkdir -p /opt/data[root@localhost ~]# chown -R mysql.mysql /opt/data/[root@localhost ~]# ll /opt/
总用量 0
drwxr-xr-x.2 mysql mysql 610月 2702:48 data
//初始化数据库
[root@localhost ~]# /usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql --datadir=/opt/data/ #这种方法初始化完成后是没有密码2021-10-26T18:48:48.601536Z 0[Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).2021-10-26T18:48:48.761083Z 0[Warning] InnoDB: New log files created, LSN=457902021-10-26T18:48:48.790067Z 0[Warning] InnoDB: Creating foreign key constraint system tables.2021-10-26T18:48:48.845455Z 0[Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID:5b1b692a-368d-11ec-a999-000c2951abda.2021-10-26T18:48:48.846389Z 0[Warning] Gtid table isnot ready to be used. Table 'mysql.gtid_executed' cannot be opened.2021-10-26T18:48:49.173882Z 0[Warning] CA certificate ca.pem is self signed.2021-10-26T18:48:49.427156Z 1[Warning] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.//生成配置文件
[root@localhost ~]# cat > /etc/my.cnf <<EOF[mysqld]
basedir =/usr/local/mysql
datadir =/opt/data
socket =/tmp/mysql.sock
port =3306
pid-file=/opt/data/mysql.pid
user = mysql
skip-name-resolve
EOF
//配置service服务启动文件
[root@localhost ~]# sed -ri 's#^(basedir=).*#\1/usr/local/mysql#g' /usr/local/mysql/support-files/mysql.server[root@localhost ~]# sed -ri 's#^(datadir=).*#\1/opt/data#g' /usr/local/mysql/support-files/mysql.server[root@localhost ~]# cat > /usr/lib/systemd/system/mysqld.service <<EOF[Unit]
Description=Mysqld server daemon
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/mysql/support-files/mysql.server start
ExecStop=/usr/local/mysql/support-files/mysql.server stop
[Install]
WantedBy=multi-user.target
EOF
//重新加载
[root@localhost ~]# systemctl daemon-reload//启动mysql
[root@localhost ~]# systemctl enable --now mysqld
Created symlink /etc/systemd/system/multi-user.target.wants/mysqld.service → /usr/lib/systemd/system/mysqld.service.[root@localhost ~]# ss -anlt
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 01280.0.0.0:800.0.0.0:*
LISTEN 01280.0.0.0:220.0.0.0:*
LISTEN 080*:3306*:*
LISTEN 0128[::]:22[::]:*//修改密码
[root@localhost ~]# mysql
Welcome to the MySQL monitor. Commands end with;or \g.
Your MySQL connection idis3
Server version:5.7.34 MySQL Community Server (GPL)
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'forhelp. Type '\c' to clear the current input statement.
mysql>set password = password('1');
Query OK,0 rows affected,1 warning (0.00 sec)
mysql> exit
Bye