mysql二进制安装脚本部署

mysql二进制安装脚本部署

单实例

[root@localhost ~]# mkdir mysql   //创建存放脚本目录
[root@localhost ~]# ls
anaconda-ks.cfg  mysql
[root@localhost ~]# cd mysql/
[root@localhost mysql]# mkdir files  //创建安装包目录
[root@localhost mysql]# ls
files
[root@localhost mysql]# ls files/
mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz
[root@localhost mysql]# touch mysql_install.sh  //创建脚本文件
[root@localhost mysql]# chmod +x mysql_install.sh  //赋予执行权限
[root@localhost mysql]# ll
total 0
drwxr-xr-x. 2 root root 56 Sep 19 21:16 files
-rwxr-xr-x. 1 root root  0 Sep 19 21:18 mysql_install.sh
[root@localhost mysql]# vim mysql_install.sh
[root@localhost mysql]# cat mysql_install.sh
#!/bin/bash

#设置执行权限
if [ $UID -ne 0 ];then
        echo "请以管理员用户进行执行"
        exit
fi
read -p "请输入要创建的实例个数: " count
read -p "请输入数据存放目录(默认路径: /opt/xbz): " datadir
read -p "请输入要为数据库设置的密码: " passwd
read -p "请输入安装目录,(默认路径:/usr/local/mysql):" mysql_install_dir
#判断安装目录合法性
echo $mysql_install_dir | grep -E '^/[a-z][a-z]*(/[a-z][a-z]*)*$' &> /dev/null
if [ $? -eq 0 ];then
    if [ ! -d $mysql_install_dir ];then
        mkdir -p $mysql_install_dir
    fi
else
    mysql_install_dir=/usr/local/mysql
fi
#判断安装目录是否为空
if [ -z $mysql_install_dir ];then
    mysql_install_dir=/usr/local/mysql
fi

#创建用户
id mysql &> /dev/null
if [ $? -ne 0 ];then
        useradd -r -M -s /sbin/nologin mysql
    else
            echo "用户已存在"
fi
#安装依赖包
dnf -y install ncurses-compat-libs --allowerasing
#解压软件包,修改目录和所属组
if [ ! -d $mysql_install_dir ];then
    echo "解压软件包"
    tar xf files/mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz -C /usr/local
    cd /usr/local
    mv mysql-5.7.38-linux-glibc2.12-x86_64 mysql
fi
chown -R mysql.mysql ${mysql_install_dir}
#设置环境变量
echo 'export PATH=${mysql_install_dir}/lib' > /etc/ld.so.conf.d/mysql.conf
#做头文件
ln -s ${mysql_install_dir}/include /usr/include/mysql
#配置lib
echo '${mysql_install_dir}/lib' > /etc/ld.so.conf.d/mysql.conf
ldconfig
#设置man文档
grep '${mysql_install_dir}/man' /etc/man_db.conf &> /dev/null
if [ $? -ne 0 ];then
        sed -i "22a MANDATORY_MANPATH                       ${mysql_install_dir}/man" /etc/man_db.conf
fi
#建立数据存放目录
for i in $(seq $count);do
    if [ $count -eq 1 ];then
            if [ -z $datadir ];then
                datadir=/opt/xbz
            fi
            if [ ! -d $datadir ];then
                mkdir -p $datadir
            fi
            chown -R mysql.mysql $datadir
            ${mysql_install_dir}/bin/mysqld --initialize --user mysql --datadir $datadir &> /tmp/passwd
#生成数据配置文件
            cat > /etc/my.cnf << EOF
[mysqld]
basedir = ${mysql_install_dir}
datadir = $datadir
socket = /tmp/mysql.sock
port = 3306
pid-file = $datadir/mysql.pid
user = mysql
skip-name-resolve
EOF
#&#x914D;&#x7F6E;&#x670D;&#x52A1;&#x542F;&#x52A8;&#x811A;&#x672C;
if [ ! -f /etc/init.d/mysqld ];then
        cp  -a   ${mysql_install_dir}/support-files/mysql.server /etc/init.d/mysqld
        sed -ri  '/^basedir=/c basedir=${mysql_install_dir}' /etc/init.d/mysqld
        sed -ri  "/^datadir=/c datadir=$datadir" /etc/init.d/mysqld
fi
chmod +x /etc/init.d/mysqld
#&#x542F;&#x52A8;mysql&#x5E76;&#x8BBE;&#x7F6E;&#x5F00;&#x673A;&#x81EA;&#x542F;
service mysqld start
sleep 6
chkconfig --add mysqld
ln -s ${mysql_install_dir}/bin/mysql /usr/bin
password=$(grep 'password' /tmp/passwd |awk '{print $NF}')
mysql -uroot -p$password --connect-expired-password -e "set password = password('$passwd');"
echo "&#x6570;&#x636E;&#x5E93;&#x7684;&#x5BC6;&#x7801;&#x662F;: $passwd"
    fi
done
&#x9A8C;&#x8BC1;&#xFF1A;
[root@localhost mysql]# mysql -uroot -p'lnh@321'
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.38 MySQL Community Server (GPL)

Copyright (c) 2000, 2022, 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> exit
Bye

使用函数的单实例

[root@localhost mysql]# cat mysql_install.sh
#!/bin/bash

#&#x8BBE;&#x7F6E;&#x6267;&#x884C;&#x6743;&#x9650;
if [ $UID -ne 0 ];then
        echo "&#x8BF7;&#x4EE5;&#x7BA1;&#x7406;&#x5458;&#x7528;&#x6237;&#x8FDB;&#x884C;&#x6267;&#x884C;"
        exit
fi

function init(){
id mysql &> /dev/null
if [ $? -ne 0 ];then
        useradd -r -M -s /sbin/nologin mysql
    else
            echo "&#x7528;&#x6237;&#x5DF2;&#x5B58;&#x5728;"
fi
#&#x5B89;&#x88C5;&#x4F9D;&#x8D56;&#x5305;
dnf -y install ncurses-compat-libs --allowerasing
#&#x89E3;&#x538B;&#x8F6F;&#x4EF6;&#x5305;,&#x4FEE;&#x6539;&#x76EE;&#x5F55;&#x548C;&#x6240;&#x5C5E;&#x7EC4;
if [ ! -d $mysql_install_dir ];then
    echo "&#x89E3;&#x538B;&#x8F6F;&#x4EF6;&#x5305;"
    tar xf files/mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz -C /usr/local
    cd /usr/local
    mv mysql-5.7.38-linux-glibc2.12-x86_64 mysql
else
    echo 'mysql&#x5DF2;&#x5B89;&#x88C5;&#xFF0C;&#x4E0D;&#x9700;&#x8981;&#x91CD;&#x590D;&#x5B89;&#x88C5;'
    exit
fi
chown -R mysql.mysql ${mysql_install_dir}
#&#x8BBE;&#x7F6E;&#x73AF;&#x5883;&#x53D8;&#x91CF;
echo 'export PATH=${mysql_install_dir}/lib' > /etc/ld.so.conf.d/mysql.conf
#&#x505A;&#x5934;&#x6587;&#x4EF6;
ln -s ${mysql_install_dir}/include /usr/include/mysql
#&#x914D;&#x7F6E;lib
echo '${mysql_install_dir}/lib' > /etc/ld.so.conf.d/mysql.conf
ldconfig
#&#x8BBE;&#x7F6E;man&#x6587;&#x6863;
grep '${mysql_install_dir}/man' /etc/man_db.conf &> /dev/null
if [ $? -ne 0 ];then
        sed -i "22a MANDATORY_MANPATH                       ${mysql_install_dir}/man" /etc/man_db.conf
fi
}
function init2(){

            if [ -z $datadir ];then
                datadir=/opt/xbz
            fi
            if [ ! -d $datadir ];then
                mkdir -p $datadir
            fi
            chown -R mysql.mysql $datadir
}

function single(){
    init
#&#x5EFA;&#x7ACB;&#x6570;&#x636E;&#x5B58;&#x653E;&#x76EE;&#x5F55;
for i in $(seq $count);do
    if [ $count -eq 1 ];then
        init2
#&#x5224;&#x65AD;&#x662F;&#x5426;&#x5DF2;&#x683C;&#x5F0F;&#x5316;
            content=$(ls -l $datadir | grep -v total | wc -l)
            if [ $content -eq 0 ];then
                ${mysql_install_dir}/bin/mysqld --initialize --user mysql --datadir $datadir &> /tmp/passwd
            else
                echo '&#x4E0D;&#x9700;&#x8981;&#x91CD;&#x590D;&#x521D;&#x59CB;&#x5316;'
                exit
            fi
#&#x751F;&#x6210;&#x6570;&#x636E;&#x914D;&#x7F6E;&#x6587;&#x4EF6;
            cat > /etc/my.cnf << EOF
[mysqld]
basedir = ${mysql_install_dir}
datadir = $datadir
socket = /tmp/mysql.sock
port = 3306
pid-file = $datadir/mysql.pid
user = mysql
skip-name-resolve
EOF
#&#x914D;&#x7F6E;&#x670D;&#x52A1;&#x542F;&#x52A8;&#x811A;&#x672C;
if [ ! -f /etc/init.d/mysqld ];then
        cp  -a   ${mysql_install_dir}/support-files/mysql.server /etc/init.d/mysqld
        sed -ri  '/^basedir=/c basedir=${mysql_install_dir}' /etc/init.d/mysqld
        sed -ri  "/^datadir=/c datadir=$datadir" /etc/init.d/mysqld
fi
chmod +x /etc/init.d/mysqld
#&#x542F;&#x52A8;mysql&#x5E76;&#x8BBE;&#x7F6E;&#x5F00;&#x673A;&#x81EA;&#x542F;
service mysqld start
sleep 6
chkconfig --add mysqld
ln -s ${mysql_install_dir}/bin/mysql /usr/bin
password=$(grep 'password' /tmp/passwd |awk '{print $NF}')
mysql -uroot -p$password --connect-expired-password -e "set password = password('$passwd');"
echo "mysql&#x5B89;&#x88C5;&#x6210;&#x529F;,&#x6570;&#x636E;&#x5E93;&#x7684;&#x5BC6;&#x7801;&#x662F;: $passwd"
    fi
done
}
read -p "&#x8BF7;&#x8F93;&#x5165;&#x8981;&#x521B;&#x5EFA;&#x7684;&#x5B9E;&#x4F8B;&#x4E2A;&#x6570;: " count
read -p "&#x8BF7;&#x8F93;&#x5165;&#x5B89;&#x88C5;&#x76EE;&#x5F55;,(&#x9ED8;&#x8BA4;&#x8DEF;&#x5F84;:/usr/local/mysql):" mysql_install_dir
read -p "&#x8BF7;&#x8F93;&#x5165;&#x6570;&#x636E;&#x5B58;&#x653E;&#x76EE;&#x5F55;(&#x9ED8;&#x8BA4;&#x8DEF;&#x5F84;: /opt/xbz): " datadir
read -p "&#x8BF7;&#x8F93;&#x5165;&#x8981;&#x4E3A;&#x6570;&#x636E;&#x5E93;&#x8BBE;&#x7F6E;&#x7684;&#x5BC6;&#x7801;(&#x9ED8;&#x8BA4;&#x5BC6;&#x7801;123456): " passwd
#&#x5224;&#x65AD;&#x5B89;&#x88C5;&#x76EE;&#x5F55;&#x5408;&#x6CD5;&#x6027;
echo $mysql_install_dir | grep -E '^/[a-z][a-z]*(/[a-z][a-z]*)*$' &> /dev/null
if [ $? -eq 0 ];then
    if [ ! -d $mysql_install_dir ];then
        mkdir -p $mysql_install_dir
    fi
else
    mysql_install_dir=/usr/local/mysql
fi
#&#x5224;&#x65AD;&#x5B89;&#x88C5;&#x76EE;&#x5F55;&#x662F;&#x5426;&#x4E3A;&#x7A7A;
if [ -z $mysql_install_dir ];then
    mysql_install_dir=/usr/local/mysql
fi
#&#x5224;&#x65AD;&#x6570;&#x636E;&#x5B58;&#x653E;&#x76EE;&#x5F55;&#x662F;&#x5426;&#x4E3A;&#x7A7A;
if [ -z $datadir ];then
    datadir=/opt/xbz
fi
#&#x5224;&#x65AD;&#x6570;&#x636E;&#x5B58;&#x653E;&#x76EE;&#x5F55;&#x662F;&#x5426;&#x5408;&#x6CD5;
echo $datadir | grep "^/[a-z][a-z]*\(/[a-z][a-z]*\)*$" &> /dev/null
if [ $? -ne 0 ];then
    datadir=/opt/xbz
fi
#&#x8BBE;&#x7F6E;&#x6570;&#x636E;&#x5E93;&#x5BC6;&#x7801;&#x683C;&#x5F0F;
if [ -z $passwd ];then
    passwd=123456
else
    echo $passwd | grep -E '[a-z]+' | grep -E '[A-Z]+' | grep -E '[0-9]+' | grep -E '_+' &> /dev/null
    if [ $? -ne 0 ] || [ ${#passwd} -lt 8 ];then
        passwd=123456
    fi
fi
#&#x521B;&#x5EFA;&#x7528;&#x6237;
if [ $count -eq 1 ];then
    single
else
    echo "&#x591A;&#x5B9E;&#x4F8B;"
fi
&#x9A8C;&#x8BC1;:
[root@localhost mysql]# mysql -uroot -p'123456'
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.38 MySQL Community Server (GPL)

Copyright (c) 2000, 2022, 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> exit
Bye

使用函数的单实例或者多实例

[root@localhost mysql]# cat mysql_install.sh
#!/bin/bash

#&#x8BBE;&#x7F6E;&#x6267;&#x884C;&#x6743;&#x9650;
if [ $UID -ne 0 ];then
        echo "&#x8BF7;&#x4EE5;&#x7BA1;&#x7406;&#x5458;&#x7528;&#x6237;&#x8FDB;&#x884C;&#x6267;&#x884C;"
        exit
fi

function init(){
id mysql &> /dev/null
if [ $? -ne 0 ];then
        useradd -r -M -s /sbin/nologin mysql
    else
            echo "&#x7528;&#x6237;&#x5DF2;&#x5B58;&#x5728;"
fi
#&#x5B89;&#x88C5;&#x4F9D;&#x8D56;&#x5305;
dnf -y install ncurses-compat-libs perl --allowerasing
#&#x89E3;&#x538B;&#x8F6F;&#x4EF6;&#x5305;,&#x4FEE;&#x6539;&#x76EE;&#x5F55;&#x548C;&#x6240;&#x5C5E;&#x7EC4;
if [ ! -d $mysql_install_dir ];then
    echo "&#x89E3;&#x538B;&#x8F6F;&#x4EF6;&#x5305;"
    tar xf files/mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz -C /usr/local
    cd /usr/local
    mv mysql-5.7.38-linux-glibc2.12-x86_64 mysql
fi
chown -R mysql.mysql ${mysql_install_dir}
#&#x8BBE;&#x7F6E;&#x73AF;&#x5883;&#x53D8;&#x91CF;
echo 'export PATH=${mysql_install_dir}/lib' > /etc/ld.so.conf.d/mysql.conf
#&#x505A;&#x5934;&#x6587;&#x4EF6;
ln -s ${mysql_install_dir}/include /usr/include/mysql
#&#x914D;&#x7F6E;lib
echo '${mysql_install_dir}/lib' > /etc/ld.so.conf.d/mysql.conf
ldconfig
#&#x8BBE;&#x7F6E;man&#x6587;&#x6863;
grep '${mysql_install_dir}/man' /etc/man_db.conf &> /dev/null
if [ $? -ne 0 ];then
        sed -i "22a MANDATORY_MANPATH                       ${mysql_install_dir}/man" /etc/man_db.conf
fi
}
function init2(){

            if [ -z $datadir ];then
                datadir=/opt/xbz
            fi
            if [ ! -d $datadir ];then
                mkdir -p $datadir
            fi
            chown -R mysql.mysql $datadir
}
#&#x5355;&#x5B9E;&#x4F8B;
function single(){
    init
#&#x5EFA;&#x7ACB;&#x6570;&#x636E;&#x5B58;&#x653E;&#x76EE;&#x5F55;
for i in $(seq $count);do
    if [ $count -eq 1 ];then
        init2
#&#x5224;&#x65AD;&#x662F;&#x5426;&#x5DF2;&#x683C;&#x5F0F;&#x5316;
            content=$(ls -l $datadir | grep -v total | wc -l)
            if [ $content -eq 0 ];then
                ${mysql_install_dir}/bin/mysqld --initialize --user mysql --datadir $datadir &> /tmp/passwd
            else
                echo '&#x4E0D;&#x9700;&#x8981;&#x91CD;&#x590D;&#x521D;&#x59CB;&#x5316;'
                exit
            fi
#&#x751F;&#x6210;&#x6570;&#x636E;&#x914D;&#x7F6E;&#x6587;&#x4EF6;
            cat > /etc/my.cnf << EOF
[mysqld]
basedir = ${mysql_install_dir}
datadir = $datadir
socket = /tmp/mysql.sock
port = 3306
pid-file = $datadir/mysql.pid
user = mysql
skip-name-resolve
EOF
#&#x914D;&#x7F6E;&#x670D;&#x52A1;&#x542F;&#x52A8;&#x811A;&#x672C;
if [ ! -f /etc/init.d/mysqld ];then
        cp  -a   ${mysql_install_dir}/support-files/mysql.server /etc/init.d/mysqld
        sed -ri  '/^basedir=/c basedir=${mysql_install_dir}' /etc/init.d/mysqld
        sed -ri  "/^datadir=/c datadir=$datadir" /etc/init.d/mysqld
fi
chmod +x /etc/init.d/mysqld
#&#x542F;&#x52A8;mysql&#x5E76;&#x8BBE;&#x7F6E;&#x5F00;&#x673A;&#x81EA;&#x542F;
service mysqld start
sleep 6
chkconfig --add mysqld
ln -s ${mysql_install_dir}/bin/mysql /usr/bin
password=$(grep 'password' /tmp/passwd |awk '{print $NF}')
mysql -uroot -p"$password" --connect-expired-password -e "set password = password('$passwd');"
echo "mysql&#x5B89;&#x88C5;&#x6210;&#x529F;,&#x6570;&#x636E;&#x5E93;&#x7684;&#x5BC6;&#x7801;&#x662F;: $passwd"
    fi
done
}
#&#x591A;&#x5B9E;&#x4F8B;
function multi(){
    init
    init2
    port=3306
#&#x914D;&#x7F6E;&#x914D;&#x7F6E;&#x6587;&#x4EF6;/etc/my.cnf
    cat > /etc/my.cnf <<eof 0 [mysqld_multi] mysqld="${mysql_install_dir}/bin/mysqld_safe" mysqladmin="${mysql_install_dir}/bin/mysqladmin" eof #创建各实例数据存放的目录并初始化各实例 for i in $(seq $count);do mkdir -p ${datadir} $port chown -r mysql.mysql content="$(ls" -l | grep -v total wc -l) if [ $content -eq ];then echo "正在初始化各实例" ${mysql_install_dir} bin --initialize --user="mysql" --datadir="${datadir}/$port" &> /tmp/passwd
#&#x53D6;&#x51FA;&#x4E34;&#x65F6;&#x6570;&#x636E;&#x5E93;&#x5BC6;&#x7801;
            password=$(grep 'password' /tmp/passwd |awk '{print $NF}')
        else
            let port++
            continue
        fi
#&#x914D;&#x7F6E;&#x914D;&#x7F6E;&#x6587;&#x4EF6;/etc/my.cnf
        cat >> /etc/my.cnf << EOF
[mysqld$port]
datadir = ${datadir}/$port
port = $port
socket = /tmp/mysql{$port}.sock
pid-file = ${datadir}/${port}/mysql_${port}.pid
log-error=/var/log/${port}.log
EOF
#&#x542F;&#x52A8;&#x5404;&#x5B9E;&#x4F8B;&#x5E76;&#x4FEE;&#x6539;&#x6570;&#x636E;&#x5E93;&#x5BC6;&#x7801;
        ln -s ${mysql_install_dir}/bin/my_print_defaults /usr/bin
        ${mysql_install_dir}/bin/mysqld_multi start ${port}
        sleep 6
        ln -s ${mysql_install_dir}/bin/mysql /usr/bin
        mysql -uroot -p"$password" -h127.0.0.1 -P${port} --connect-expired-password -e "set password = password('$passwd');"
        let port++
    done
    echo "mysql&#x5B89;&#x88C5;&#x6210;&#x529F;,&#x6570;&#x636E;&#x5E93;&#x7684;&#x5BC6;&#x7801;&#x662F;: $passwd"
}

read -p "&#x8BF7;&#x8F93;&#x5165;&#x8981;&#x521B;&#x5EFA;&#x7684;&#x5B9E;&#x4F8B;&#x4E2A;&#x6570;: " count
read -p "&#x8BF7;&#x8F93;&#x5165;&#x5B89;&#x88C5;&#x76EE;&#x5F55;,(&#x9ED8;&#x8BA4;&#x8DEF;&#x5F84;:/usr/local/mysql):" mysql_install_dir
read -p "&#x8BF7;&#x8F93;&#x5165;&#x6570;&#x636E;&#x5B58;&#x653E;&#x76EE;&#x5F55;(&#x9ED8;&#x8BA4;&#x8DEF;&#x5F84;: /opt/xbz): " datadir
read -p "&#x8BF7;&#x8F93;&#x5165;&#x8981;&#x4E3A;&#x6570;&#x636E;&#x5E93;&#x8BBE;&#x7F6E;&#x7684;&#x5BC6;&#x7801;(&#x9ED8;&#x8BA4;&#x5BC6;&#x7801;123456): " passwd
#&#x5224;&#x65AD;&#x5B89;&#x88C5;&#x76EE;&#x5F55;&#x5408;&#x6CD5;&#x6027;
echo $mysql_install_dir | grep -E '^/[a-z][a-z]*(/[a-z][a-z]*)*$' &> /dev/null
if [ $? -eq 0 ];then
    if [ ! -d $mysql_install_dir ];then
        mkdir -p $mysql_install_dir
    fi
else
    mysql_install_dir=/usr/local/mysql
fi
#&#x5224;&#x65AD;&#x5B89;&#x88C5;&#x76EE;&#x5F55;&#x662F;&#x5426;&#x4E3A;&#x7A7A;
if [ -z $mysql_install_dir ];then
    mysql_install_dir=/usr/local/mysql
fi
#&#x5224;&#x65AD;&#x6570;&#x636E;&#x5B58;&#x653E;&#x76EE;&#x5F55;&#x662F;&#x5426;&#x4E3A;&#x7A7A;
if [ -z $datadir ];then
    datadir=/opt/xbz
fi
#&#x5224;&#x65AD;&#x6570;&#x636E;&#x5B58;&#x653E;&#x76EE;&#x5F55;&#x662F;&#x5426;&#x5408;&#x6CD5;
echo $datadir | grep "^/[a-z][a-z]*\(/[a-z][a-z]*\)*$" &> /dev/null
if [ $? -ne 0 ];then
    datadir=/opt/xbz
fi
#&#x8BBE;&#x7F6E;&#x6570;&#x636E;&#x5E93;&#x5BC6;&#x7801;&#x683C;&#x5F0F;
if [ -z $passwd ];then
    passwd=123456
else
    echo $passwd | grep -E '[a-z]+' | grep -E '[A-Z]+' | grep -E '[0-9]+' | grep -E '_+' &> /dev/null
    if [ $? -ne 0 ] || [ ${#passwd} -lt 8 ];then
        passwd=123456
    fi
fi
#&#x521B;&#x5EFA;&#x7528;&#x6237;
if [ $count -eq 1 ];then
    single
    ss -antl
else
    multi
    ss -antl
fi
&#x9A8C;&#x8BC1;:
[root@localhost mysql]# mysql -uroot -p'123456' -h127.0.0.1 -P3306
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.38 MySQL Community Server (GPL)

Copyright (c) 2000, 2022, 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> exit
Bye
[root@localhost mysql]# mysql -uroot -p'123456' -h127.0.0.1 -P3307
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.38 MySQL Community Server (GPL)

Copyright (c) 2000, 2022, 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> exit
Bye
[root@localhost mysql]# mysql -uroot -p'123456' -h127.0.0.1 -P3308
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.38 MySQL Community Server (GPL)

Copyright (c) 2000, 2022, 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> exit
Bye

</eof>

Original: https://www.cnblogs.com/tushanbu/p/16711987.html
Author: 涂山布
Title: mysql二进制安装脚本部署

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/573952/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

  • Jq 手机端输入框防止底部菜单被小键盘弹起

    var winHeight = $(window).height(); //获取当前页面高度 $(window).resize(function () { var thisHeig…

    Linux 2023年6月7日
    085
  • 符号转义解决SSH远程命令执行的问题

    场景:服务器 A B C D 上存在一些日志,日志中的每行包含了日期、日志级别、日志信息等。现在要求从跳板机 X 获取这四台服务器上的数据,并通过规则(如日期)筛选,汇总到一个文件…

    Linux 2023年6月14日
    088
  • redis数据结构附录

    引言 本次对上一次的数据结构知识进行补充,主要有redis数据结构的相关应用场景和内存相关知识 引用计数-内存 redis中的对象回收机制是采用引用计数的方式,首先我们可以通过re…

    Linux 2023年6月13日
    091
  • MySQL数据库用户授权

    相关库:mysql 相关表:user 查看权限表: 5.7之前的版本 select user,host,password from mysql.user; 5.7之后的版本 sel…

    Linux 2023年6月14日
    075
  • 多表查询练习题

    十道多表查询练习题 准备数据: 查询所有的课程的名称以及对应的任课老师姓名 查询姓李老师的个数 查询挂科超过两门(包括两门)的学生姓名和班级、查询选修了所有课程的学生姓名 post…

    Linux 2023年6月7日
    094
  • Java基础系列–09_集合2

    昨天介绍了集合的主要架构体系,今天主要的目的是学习集合的迭代器的遍历和List的特有功能。 迭代器:概述: 由于多种集合的数据结构不同,所以存储方式不同,取出方式也不同。但是他们都…

    Linux 2023年6月7日
    073
  • FinalShell—一体化服务器管理软件(SSH客户端)

    下面附上一些截图和官方连接: 官网:http://www.hostbuf.com/ FinalShell是一体化的的服务器,网络管理软件,不仅是ssh客户端,还是功能强大的开发,运…

    Linux 2023年5月28日
    075
  • Spring事务(四)-事务隔离级别

    Spring @Transactional注解isolation属性 @Transactional注解通过isolation属性设置事务隔离级别。如下: @Transactiona…

    Linux 2023年6月6日
    072
  • docker-compose安装,yml文件配置

    1、离线安装 https://github.com/docker/compose/releases 移动文件 mv docker-compose-linux-x86_64 /usr…

    Linux 2023年6月14日
    085
  • 添加SSH服务

    1、基于commit命令创建 1.1 启动容器 [root@master ~]# docker run -it ubuntu:18.04 bash #&#x66F4;&am…

    Linux 2023年6月13日
    086
  • shell xargs技巧

    find /home/tomcat8-hk/ -name ‘808*.sh’ | xargs -i sed ‘s@CATALINA_HOME=&…

    Linux 2023年5月28日
    096
  • python串口助手

    最近项目中要使用模拟数据源通过向外发送数据,以前都是用C#编写,最近在研究python,所以就用python写了一个串口助手,方便以后的测试。 在电脑上通过虚拟串口助手产生两个虚拟…

    Linux 2023年6月14日
    097
  • C++ NFS挂载

    挂载NFS 挂载NFS时,常用的命令比如: #将远程目录挂载到本地/home/share目录下 mount -t nfs -o nolock 192.168.1.10:/tmp /…

    Linux 2023年6月8日
    075
  • Xshell配置ssh免密码登录-密钥公钥(Public key)与私钥(Private Key)登录【已成功实例】

    本文转自https://blog.csdn.net/qjc_501165091/article/details/51278696 ssh登录提供两种认证方式:口令(密码)认证方式和…

    Linux 2023年5月28日
    084
  • python 练习题:接收一个或多个数并计算乘积

    以下函数允许计算两个数的乘积,请稍加改造,变成可接收一个或多个数并计算乘积 def product(x, y): return x * y python;gutter:true; …

    Linux 2023年6月8日
    094
  • 面向对象设计的23种设计模式

    设计模式(Design pattern)代表了最佳的实践,通常被有经验的面向对象的软件开发人员所采用。设计模式是软件开发人员在软件开发过程中面临的一般问题的解决方案。这些解决方案是…

    Linux 2023年6月7日
    096
亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球