MySQL——centos一键安装mysql8、自动登录mysql脚本

系统:centos
注:每个人的系统环境不同,所以这里的依赖包可能不全

#!/usr/bin/bash
#下载依赖包
yum install -y openssl-devel.x86_64 openssl.x86_64 
yum install -y libaio.x86_64 libaio-devel.x86_64 
yum install -y perl.x86_64 perl-devel.x86_64 
yum install -y perl-JSON.noarch 
yum install -y autoconf 
yum install -y wget
yum install -y net-tools

systemctl stop firewalld.service
systemctl disable firewalld.service#关闭防火墙
#下载mysql8
wget http://mirrors.sohu.com/mysql/MySQL-8.0/mysql-8.0.13-1.el7.x86_64.rpm-bundle.tar
tar -xvf ./*.tar

#再下载依赖包
yum install numactl

rpm -ivh mysql-community-common-8.0.13-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-8.0.13-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-8.0.13-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-8.0.13-1.el7.x86_64.rpm

mysqld --initialize --console
chown -R mysql:mysql /var/lib/mysql/
systemctl start mysqld

查看初始密码

grep 'temporary password' /var/log/mysqld.log

在这里插入图片描述
修改密码(初次登陆必须)
alter user ‘root’@‘localhost’ identified by ‘urpassword’;

show databases;
输入quit退出数据库
MySQL——centos一键安装mysql8、自动登录mysql脚本_第1张图片

自动登录

#!/usr/bin/expect
set timeout 3
spawn mysql -u root -p
expect {
"password:" {send "密码\r"};
}
expect {
"mysql>" {send "show databases;\r"};
}
interact

你可能感兴趣的:(MySQL——centos一键安装mysql8、自动登录mysql脚本)