二进制部署mysql5.7.24
数据库包下载地址:https://downloads.mysql.com/archives/community/
选择自己的目标版本

1、上传下载的二进制包,解压并创建软连接
#解压到/usr/local目录下 [root@master ~]# tar xf mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz -C /usr/local/ [root@master ~]# cd /usr/local/ #在/usr/local目录下创建软连接 [root@master /usr/local]# ln -sv mysql-5.7.18-linux-glibc2.5-x86_64/ mysql "mysql" -> "mysql-5.7.18-linux-glibc2.5-x86_64/"
2、新建mysql用户组和mysql用户
[root@master /usr/local]# groupadd mysql
[root@master /usr/local]# useradd -g mysql -r -s /sbin/nologin -M -d /data/mysqldata mysql
3、新建数据目录并赋予相关属主属组及权限
[root@master /usr/local]# chown -R mysql:mysql /usr/local/mysql/ [root@master /usr/local]# mkdir -p /data/mysqldata [root@master /usr/local]# chmod -R 770 /data/mysqldata [root@master /usr/local]# chown -R mysql:mysql /data/mysqldata
4、初始化mysqld,生成mysql的初始密码
[root@master /usr/local]# cd /usr/local/mysql #初始化mysqld(会提示有个报错,缺少libaio插件) [root@master /usr/local/mysql]# ./bin/mysqld --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysqldata --initialize ./bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory #安装libaio [root@master /usr/local/mysql]# yum install -y libaio #再次初始化mysqld,日志最下方输出mysql初始密码 (hS9Le#Ki9dM [root@master /usr/local/mysql]# ./bin/mysqld --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysqldata --initialize 2020-12-24T07:39:53.161470Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2020-12-24T07:39:56.359351Z 0 [Warning] InnoDB: New log files created, LSN=45790 2020-12-24T07:39:56.836233Z 0 [Warning] InnoDB: Creating foreign key constraint system tables. 2020-12-24T07:39:56.952342Z 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: 383afe3f-45bb-11eb-a3ec-ca28bacb4f17. 2020-12-24T07:39:56.976172Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened. 2020-12-24T07:39:56.976892Z 1 [Note] A temporary password is generated for root@localhost: (hS9Le#Ki9dM
5、配置环境变量
#配置环境变量 [root@master /usr/local/mysql]# echo "PATH=$PATH:/usr/local/mysql/bin" > /etc/profile.d/mysql.sh [root@master /usr/local/mysql]# source /etc/profile.d/mysql.sh
6、使用system管理mysqld服务
#编写system文件,使用systemctl来管理mysqld服务 [root@master /usr/local/mysql]# vim /usr/lib/systemd/system/mysql.service [Unit] Description=MySQL Server After=network.target [Install] WantedBy=multi-user.target [Service] Type=forking TimeoutSec=0 PermissionsStartOnly=true
ExecStart=/usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysqldata --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/data/mysqldata/master.err --pid-file=/data/mysqldata/master.pid --socket=/tmp/mysql.sock --port=3306 --daemonize 或者 ExecStart=/usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf --daemonize 其他的配置文件配置到 --defaults-file=/etc/my.cnf LimitNOFILE = 65535 Restart=on-failure RestartSec=3 RestartPreventExitStatus=1 PrivateTmp=false #重载systemctl配置 [root@master /usr/local/mysql]# systemctl daemon-reload #使用systemctl命令启动mysql服务 [root@master /usr/local/mysql]# systemctl start mysql.service [root@master /usr/local/mysql]# ps aux |grep mysql mysql 19178 3.6 34.2 1190144 171508 ? Sl 16:00 0:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysqldata --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/data/mysqldata/master.err --pid-file=/data/mysqldata/master.pid --socket=/tmp/mysql.sock --port=3306 --daemonize root 19208 0.0 0.1 112660 932 pts/1 S+ 16:00 0:00 grep --color=auto mysql
systemctl enable mysql.service ---设置开启自启动
systemctl start mysql.service ----开启此服务
systemctl stop mysql.service -----关闭此服务
systemctl restart mysql.service -----重启此服务
systemctl status mysql.service -----查看服务状态
7、登录mysql并修改密码
#如果密码有通配符,可以用单引号括起来,或者在交互模式粘贴 [root@master /usr/local/mysql]# mysql -uroot -p'(hS9Le#Ki9dM' 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 3 Server version: 5.7.18 Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved. 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> set password='123456'; mysql> use mysql; mysql> update user set host = '%' where user = 'root'; mysql> FLUSH PRIVILEGES; mysql> exit [root@master /usr/local/mysql]# mysql -uroot -p

浙公网安备 33010602011771号