首页 > 数据库 >【MySQL】二进制安装MySQL

【MySQL】二进制安装MySQL

时间:2023-06-08 14:00:12浏览次数:41  
标签:linux 8.0 二进制 安装 MySQL dev local mysql root

一、基于Ubuntu 二进制安装MySQL8.0 (5.7+适用)

1、创建用户

[root@Node-Ubuntu1804-20:~]# groupadd mysql
[root@Node-Ubuntu1804-20:~]# useradd -r -g mysql -s /usr/sbin/nologin mysql

 

2、创建目录

[root@Node-Ubuntu1804-20:~]# mkdir /data/mysql -p
[root@Node-Ubuntu1804-20:~]# chown -R mysql.mysql /data/mysql/

  

3、准备二进制程序

下载链接:https://cdn.mysql.com/archives/mysql-8.0/mysql-8.0.32-linux-glibc2.12-x86_64.tar

 

[root@Node-Ubuntu1804-20:~]# wget https://cdn.mysql.com/archives/mysql-8.0/mysql-8.0.32-linux-glibc2.12-x86_64.tar
[root@Node-Ubuntu1804-20:~]# tar xvf mysql-8.0.32-linux-glibc2.12-x86_64.tar
mysql-test-8.0.32-linux-glibc2.12-x86_64.tar.xz
mysql-8.0.32-linux-glibc2.12-x86_64.tar.xz
mysql-router-8.0.32-linux-glibc2.12-x86_64.tar.xz
[root@Node-Ubuntu1804-20:~]# tar xf mysql-8.0.32-linux-glibc2.12-x86_64.tar.xz -C /usr/local/
[root@Node-Ubuntu1804-20:~]# cd /usr/local/
[root@Node-Ubuntu1804-20:/usr/local]# ln -sv mysql-8.0.32-linux-glibc2.12-x86_64 mysql
'mysql' -> 'mysql-8.0.32-linux-glibc2.12-x86_64'

  

4、安装依赖包

[root@Node-Ubuntu1804-20:~]# apt install -y libaio1 libaio-dev libncurses5-dev
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages were automatically installed and are no longer required:
  linux-headers-4.15.0-151 linux-headers-4.15.0-151-generic linux-image-4.15.0-151-generic linux-modules-4.15.0-151-generic
  linux-modules-extra-4.15.0-151-generic
Use 'apt autoremove' to remove them.
The following additional packages will be installed:
  libtinfo-dev
Suggested packages:
  ncurses-doc
The following NEW packages will be installed:
  libaio-dev libaio1 libncurses5-dev libtinfo-dev
0 upgraded, 4 newly installed, 0 to remove and 71 not upgraded.
Need to get 275 kB of archives.
After this operation, 1510 kB of additional disk space will be used.
Get:1 http://cn.archive.ubuntu.com/ubuntu bionic-updates/main amd64 libaio1 amd64 0.3.110-5ubuntu0.1 [6476 B]
Get:2 http://cn.archive.ubuntu.com/ubuntu bionic-updates/main amd64 libaio-dev amd64 0.3.110-5ubuntu0.1 [12.8 kB]
Get:3 http://cn.archive.ubuntu.com/ubuntu bionic-updates/main amd64 libtinfo-dev amd64 6.1-1ubuntu1.18.04.1 [81.4 kB]
Get:4 http://cn.archive.ubuntu.com/ubuntu bionic-updates/main amd64 libncurses5-dev amd64 6.1-1ubuntu1.18.04.1 [174 kB]
Fetched 275 kB in 2s (123 kB/s)      
Selecting previously unselected package libaio1:amd64.
(Reading database ... 144068 files and directories currently installed.)
Preparing to unpack .../libaio1_0.3.110-5ubuntu0.1_amd64.deb ...
Unpacking libaio1:amd64 (0.3.110-5ubuntu0.1) ...
Selecting previously unselected package libaio-dev:amd64.
Preparing to unpack .../libaio-dev_0.3.110-5ubuntu0.1_amd64.deb ...
Unpacking libaio-dev:amd64 (0.3.110-5ubuntu0.1) ...
Selecting previously unselected package libtinfo-dev:amd64.
Preparing to unpack .../libtinfo-dev_6.1-1ubuntu1.18.04.1_amd64.deb ...
Unpacking libtinfo-dev:amd64 (6.1-1ubuntu1.18.04.1) ...
Selecting previously unselected package libncurses5-dev:amd64.
Preparing to unpack .../libncurses5-dev_6.1-1ubuntu1.18.04.1_amd64.deb ...
Unpacking libncurses5-dev:amd64 (6.1-1ubuntu1.18.04.1) ...
Setting up libtinfo-dev:amd64 (6.1-1ubuntu1.18.04.1) ...
Setting up libncurses5-dev:amd64 (6.1-1ubuntu1.18.04.1) ...
Setting up libaio1:amd64 (0.3.110-5ubuntu0.1) ...
Setting up libaio-dev:amd64 (0.3.110-5ubuntu0.1) ...
Processing triggers for man-db (2.8.3-2ubuntu0.1) ...
Processing triggers for libc-bin (2.27-3ubuntu1.5) ...

  

5、设置PATH环境变量

[root@Node-Ubuntu1804-20:~]# echo "PATH=/usr/local/mysql/bin:$PATH" > /etc/profile.d/mysql.sh
[root@Node-Ubuntu1804-20:~]# . /etc/profile.d/mysql.sh 

 

6、创建配置文件

[root@Node-Ubuntu1804-20:~]# vim /etc/my.cnf
[root@Node-Ubuntu1804-20:~]# cat /etc/my.cnf
[mysqld]
datadir=/data/mysql
socket=/data/mysql/mysql.sock
pid-file=/data/mysql/mysql.pid
log-error=/data/mysql/mysql.log

[client]
socket=/data/mysql/mysql.sock

  

7、创建数据库文件,并提取root密码

[root@Node-Ubuntu1804-20:~]# mysqld --initialize --user=mysql --datadir=/data/mysql
[root@Node-Ubuntu1804-20:~]# grep password /data/mysql/mysql.log 2023-06-07T02:05:13.924955Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: k.k/j&XuT7uF [root@Node-Ubuntu1804-20:~]# awk '/temporary password/{print $NF}' /data/mysql/mysql.log k.k/j&XuT7uF

  

8、创建服务脚本,并启动服务

[root@Node-Ubuntu1804-20:~]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@Node-Ubuntu1804-20:~]# /etc/init.d/mysqld start
[ ok ] Starting mysqld (via systemctl): mysqld.service.

  

9、修改初始密码,测试访问数据库

[root@Node-Ubuntu1804-20:~]# mysqladmin -uroot -p'k.k/j&XuT7uF' password 'mysql'
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.

[root@Node-Ubuntu1804-20:~]# mysql -uroot -pmysql
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 12
Server version: 8.0.32 MySQL Community Server - GPL

Copyright (c) 2000, 2023, 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> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.00 sec)

mysql> 

  

二、基于CentOS7  二进制安装MySQL8.0(5.7+适用)

1、创建用户

[root@node-centos7-70 ~]# groupadd mysql
[root@node-centos7-70 ~]# useradd -r -g mysql -s /usr/sbin/nologin mysql

 

2、创建目录
[root@node-centos7-70 ~]# mkdir /data/mysql -p
[root@node-centos7-70 ~]# chown -R mysql.mysql /data/mysql

 

3、准备二进制程序

[root@node-centos7-70 ~]# wget https://cdn.mysql.com/archives/mysql-8.0/mysql-8.0.32-linux-glibc2.12-x86_64.tar
--2023-06-07 10:54:29--  https://cdn.mysql.com/archives/mysql-8.0/mysql-8.0.32-linux-glibc2.12-x86_64.tar
正在解析主机 cdn.mysql.com (cdn.mysql.com)... 104.70.237.54
正在连接 cdn.mysql.com (cdn.mysql.com)|104.70.237.54|:443... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:1005660160 (959M) [application/x-tar]
正在保存至: “mysql-8.0.32-linux-glibc2.12-x86_64.tar”

100%[====================================================================================================>] 1,005,660,160 26.6MB/s 用时 29s    

2023-06-07 10:54:58 (32.8 MB/s) - 已保存 “mysql-8.0.32-linux-glibc2.12-x86_64.tar” [1005660160/1005660160])

[root@node-centos7-70 ~]# tar xvf mysql-8.0.32-linux-glibc2.12-x86_64.tar
mysql-test-8.0.32-linux-glibc2.12-x86_64.tar.xz
mysql-8.0.32-linux-glibc2.12-x86_64.tar.xz
mysql-router-8.0.32-linux-glibc2.12-x86_64.tar.xz
[root@node-centos7-70 ~]# tar xf mysql-8.0.32-linux-glibc2.12-x86_64.tar.xz -C /usr/local/
[root@node-centos7-70 ~]# cd /usr/local
[root@node-centos7-70 local]# ln -sv mysql-8.0.32-linux-glibc2.12-x86_64 mysql
"mysql" -> "mysql-8.0.32-linux-glibc2.12-x86_64"

 

4、安装依赖包

[root@node-centos7-70 ~]# yum install -y libaio numactl-libs

 

5、设置PATH环境变量

[root@node-centos7-70 ~]# echo "PATH=/usr/local/mysql/bin:$PATH" > /etc/profile.d/mysql.sh
[root@node-centos7-70 ~]# . /etc/profile.d/mysql.sh

 

6、创建配置文件

[root@node-centos7-70 ~]# tee > /etc/my.cnf << EOF
[mysqld]
datadir=/data/mysql
socket=/data/mysql/mysql.sock
pid-file=/data/mysql/mysql.pid
log-error=/data/mysql/mysql.log

[client]
socket=/data/mysql/mysql.sock
EOF

 

7、创建数据库文件,并提取root密码

[root@node-centos7-70 ~]# mysqld --initialize --user=mysql --datadir=/data/mysql
[root@node-centos7-70 ~]# grep password /data/mysql/mysql.log
2023-06-07T03:20:09.342795Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: ,*9LyAr6wrr#
[root@node-centos7-70 ~]# awk '/temporary password/{print $NF}' /data/mysql/mysql.log 
,*9LyAr6wrr#

 

8、创建服务脚本,并启动服务

[root@node-centos7-70 ~]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@node-centos7-70 ~]# chkconfig --add mysqld
[root@node-centos7-70 ~]# service mysqld start
Starting MySQL... SUCCESS! 

 

 

9、修改初始密码,测试访问数据库

 

[root@node-centos7-70 ~]# mysqladmin -uroot -p',*9LyAr6wrr#' password 'mysql'
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.
[root@node-centos7-70 ~]# mysql -uroot -pmysql
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 9
Server version: 8.0.32 MySQL Community Server - GPL

Copyright (c) 2000, 2023, 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> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.00 sec)

mysql> 

 

三、shell 二进制一键安装 Mysql => 5.7+

 

#!/bin/bash
#
#********************************************************************
#Author:                janzen
#Date:                  2023-06-07
#FileName:             mysql_install.sh
#Description:          The test script
#Copyright (C):        2023 All rights reserved
#********************************************************************
ERR="echo -e \033[1;31m"
SUC="echo -e \033[1;32m"
WAR="echo -e \033[1;33m"
RED="\033[1;31m"
GRE="\033[1;32m"
YEL="\033[1;33m"
END="\033[m"

VERSION=$1
VERSION=${VERSION:-'8.0.32'}
MAIN_VERSION=`echo ${VERSION: 0:3}`
MYSQL="mysql-$VERSION-linux-glibc2.12-x86_64.tar"
URL="https://cdn.mysql.com/archives/mysql-$MAIN_VERSION/"
SRC='/tmp/'
MYSQL_DATA=/data/mysql
PASSWD='mysql'

os_type(){
grep centos /etc/os-release &> /dev/null && { echo "centos";return 0;} || grep ubuntu /etc/os-release &> /dev/null && { echo ubuntu; return 0;} || grep "Red Hat" /etc/os-release &> /dev/null && { echo "rhel";return 0; } || { echo "";return 1;}
}
wait_sec(){
        local ERR=${ERR:-"echo -e \e[1;31m"}
        local SUC=${SUC:-"echo -e \e[1;32m"}
        local WAR=${WAR:-"echo -e \e[1;33m"}
        local RED=${RED:-"\e[1;31m"}
        local GRE=${GRE:-"\e[1;32m"}
        local YEL=${YEL:-"\e[1;33m"}
        local END=${END:-"\e[m"}
        local sec=$1
        local STR=$2
        local STR=${STR:-"Waiting for "}
        local sec=${sec:-10}
        local mark='>'
        
        $WAR"$STR($sec s) ......"$END
        for i in `eval echo {1..$sec}`;do
                printf "$YEL Waiting: [%-${sec}s]%ds\r $END" "${mark}" "${i}"
                mark=">${mark}"
                sleep 1
        done
        echo
}

check() {
    mysql -V &> /dev/null || mysqld -V &> /dev/null && { $ERR"Mysql 已安装,程序退出"$END; exit 1;}
    [ $UID -ne 0 ] && { $ERR"当前用户非root用户,请切换用户后重试"$END; exit 1;}
    [ -e /usr/local/mysql ] && { $ERR"Mysql 已存在,程序退出"$END; exit 1;}
    [ -e "$SRC$MYSQL.xz" ] || [ -e "$SRC$MYSQL.gz" ] && $WAR"检测到程序包已存在 `ls $SRC$MYSQL*`"$END || DOWNLOAD=1
    $SUC"初始环境检查完成"$END
    echo
}

install_mysql() {
    wait_sec $1 $2
    if [ $DOWNLOAD ]; then
        $WAR"本地安装程序不存在,开始联网下载程序包"$END
        wget -P $SRC "$URL$MYSQL.xz" || wget -P $SRC "$URL$MYSQL.gz" || { $ERR"无法连接目标地址"$END;exit 1; }
    fi
    tar xf "$SRC$MYSQL.xz" -C /usr/local/ &> /dev/null || tar xf "$SRC$MYSQL.gz" -C /usr/local/ &> /dev/null || { $ERR"未找到目标安装包"$END;exit 1; }
    MYSQL_DIR=`echo -e "$MYSQL" | sed -nr 's/(^.*)\.tar*/\1/p'`
    cd /usr/local
    [ -e $MYSQL_DIR ] && ln -sv $MYSQL_DIR mysql || { $ERR$MYSQL_DIR" not exists"$END;exit 1; }
    id mysql > /dev/null || useradd -s /sbin/nogin -r mysql
    mkdir -p $MYSQL_DATA
    chown mysql.mysql $MYSQL_DATA
    echo "PATH=/usr/local/mysql/bin:$PATH" > /etc/profile.d/mysql.sh
    chmod a+x /etc/profile.d/mysql.sh
    source /etc/profile.d/mysql.sh
    export "PATH=/usr/local/mysql/bin:$PATH"

    if [ `os_type` == 'centos' ]; then
        yum install -y libaio numactl-libs
    elif [ `os_type` == 'ubuntu' ]; then
        apt install -y libaio1 libaio-dev libncurses5-dev || { rm -f {/var/lib/apt/lists/lock,/var/cache/apt/archives/lock,/var/lib/dpkg/lock*}; dpkg --configure -a; sleep 5; apt install -y libaio1 libaio-dev libncurses5-dev; } && $SUC"安装依赖包成功"$END || { $ERR"安装依赖包失败"$END; exit 1;}
    fi

    tee > /etc/my.cnf << EOF
[mysqld]
datadir=$MYSQL_DATA
socket=$MYSQL_DATA/mysql.sock
pid-file=$MYSQL_DATA/mysql.pid
log-error=$MYSQL_DATA/mysql.log

[client]
socket=$MYSQL_DATA/mysql.sock
EOF
    cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
    mysqld --initialize --user=mysql --datadir=$MYSQL_DATA
    DEFT_PASSWD=`awk '/temporary password/{print $NF}' $MYSQL_DATA/mysql.log`
    /etc/init.d/mysqld start
    if [ `os_type` == 'centos' ]; then
        chkconfig --add mysqld
        chkconfig on
    elif [ `os_type` == 'ubuntu' ]; then
        tee >> /lib/systemd/system/rc-local.service << EOF
[Install]
WantedBy=multi-user.target
Alias=rc-local.service
EOF
        tee > '/etc/rc.local' << EOF
#!/bin/bash                                                                                                                                     
/etc/init.d/mysqld start
EOF
        chmod a+x /etc/rc.local
        ln -sf /lib/systemd/system/rc-local.service  /etc/systemd/system/rc-local.service 
        systemctl daemon-reload
        systemctl restart rc-local.service
    fi
    mysqladmin -uroot -p"$DEFT_PASSWD" password "$PASSWD"
    mysql -uroot -p"$PASSWD" -e "show databases;" &> /dev/null && $SUC"MySQL数据库运行成功"$END || { $ERR"MySQL数据库运行失败"$END;return 1; }
}

check
install_mysql 10 "即将开始安装数据库"

 

 

标签:linux,8.0,二进制,安装,MySQL,dev,local,mysql,root
From: https://www.cnblogs.com/Janzen-q/p/17462696.html

相关文章

  • mysql xplugin mysqlx
    https://dev.mysql.com/doc/refman/8.0/en/x-plugin-options-system-variables.html  Bydefault,foritsXpluginfeatures,MySQLlistensonport33060,boundtoallIPaddresses.See manualsectiononXpluginoptionsandsystemvariables (indicatingdefau......
  • python 安装包、基础学习资料、代码应用示例
    安装包python-3.7.0.rar链接:https://pan.baidu.com/s/1Gl5QUMrLFoTekENighd0iw提取码:ysgxpycharm5.0.3.zip链接:https://pan.baidu.com/s/1DpzRiMWSW2byWjB1cYmQKw提取码:9rgiAnaconda3jupyternotebook第一步进入:https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/第......
  • Docker(六):安装可视化面板Portainer
    一、Portainer是什么Portainer是一个Docker的图形可视化工具,能够提供一个交互界面显示Docker的详细信息供用户操作。二、Portainer安装1.下载Protainer镜像dockerpullportainer/portainer2.创建容器并启动dockerrun-d-p9000:9000--restart=always-v/var/run/doc......
  • win10配置Electron安装环境以及解决报错
    学习electron做桌面应用程序开发,从安装到HellowWorld,过程中遇到的问题以及解决方式。开始学习这边Electron官方文档有详细的步骤。基本要求检查Node.js是否正确安装,请在您的终端输入以下命令:node-vnpm-v创建程序Electron应用程序遵循与其他Node.js项目相同的结构......
  • MySQL索引的数据结构
    一:索引概述MySQL官方对索引的定义为:索引(Index)是帮助MySQL高效获取数据的数据结构。索引的本质:索引是数据结构。可以简单理解为“排好序的快速查找数据结构”,满足特定查找算法。这些数据结构以某种方式指向数据,这样就可以在这些数据结构的基础上实现高级查找算法。1:索引优缺点......
  • 虚拟机上安装nginx、openssl、pcre、zlib步骤
    1、下载相关组件:wget http://nginx.org/download/nginx-1.10.2.tar.gzopenssl是一个开源的实现加解密和证书的专业系统。wget http://www.openssl.org/source/openssl-fips-2.0.10.tar.gzopenssl是一个开源的实现加解密和证书的专业系统。wgethttp://downloads.sourcefo......
  • mysql8.0设置时区
    在MySQL8.0中,可以使用以下命令查看当前数据库系统的时区设置:SELECT@@global.time_zone;该命令将返回一个字符串,表示当前数据库系统的时区设置。例如,返回如下结果:+--------------------+|@@global.time_zone|+--------------------+|SYSTEM|+------......
  • mysql常见的时间查询语句
    mysql数据库要按当天、昨天、前七日、近三十天、季度、年查询查询今天select*from表名whereto_days(时间字段名)=to_days(now());   查询昨天SELECT*FROM表名WHERETO_DAYS(NOW())-TO_DAYS(`时间字段名`)=1 查询7天 sql语句SELECT*FROM表名whereDATE_SUB(CU......
  • linux下安装erlang
    1.安装依赖环境:1)安装GCCGCC-C++Openssl等模块,安装过就不需要安装了yum-yinstallmakegccgcc-c++kernel-develm4ncurses-developenssl-devel 2)安装ncursesyum-yinstallncurses-devel2.下载erlang:官网下载:http://erlang.org/download/或者直接下载[root@manmanda20......
  • centos7 部署 Mysql 5.7
    (centos7部署Mysql5.7)一、安装2.1环境准备1、查看系统自带或之前安装的mariadb。rpm-qa|grepmariadb2、卸载它们rpm-e--nodepsmariadb-libs-5.5.60-1.el7_5.x86_643、再看一下之前有没有安装过mysqlrpm-qa|grepmysql如果没有这里不会有任何的返回,如......