当前位置:网站首页>Ubuntu安装mysql压缩包备查
Ubuntu安装mysql压缩包备查
2022-06-13 10:38:00 【m0_60725291】
目录
#!/usr/bin/env bash
#parameter definition
a=$(uname -a)
curdir=$( cd $(dirname $0) pwd )
curuser=$USER
mysqltarfile=$(ls -l | grep tar.xz | awk '{print $9}')
log=$curdir/mysql_install.log
# 解压MYSQL安装包
function deCompression() {
echo '==========解压MYSQL安装包=========='
pushd $curdir
tar -Jxvf $mysqltarfile -C /usr/local/
mv /usr/local/mysql-8.0.29-linux-glibc2.17-x86_64-minimal /usr/local/mysql
if [ $? -ne 0 ]; then
echo 'MySQL decompression failed!!!'
exit
else
echo '===================================='
echo 'MySQL decompression success!'
fi
popd
}
# 创建MYSQL⽤户和⽤户组
function createMysqlGroup() {
echo '==========创建MYSQL⽤户和⽤户组=========='
groupadd mysql
useradd -g mysql mysql
# mkdir /usr/local/mysql/data
chown -R mysql:mysql /usr/local/mysql
echo '===================================='
echo 'mysql group created success!'
}
# MYSQL的配置⽂件,可修改datadir
function mycnf() {
cat >/etc/my.cnf <<EOF [mysql] default-character-set=UTF8MB4 socket=/var/lib/mysql/mysql.sock [mysqld] skip-name-resolve port = 3306 socket=/var/lib/mysql/mysql.sock basedir=/usr/local/mysql datadir=/usr/local/mysql/data max_connections=200 character-set-server=UTF8MB4 default-storage-engine=INNODB lower_case_table_names=1 max_allowed_packet=32M EOF
if [ $? -ne 0 ]; then
echo 'Failed to write the my.cnf configuration file!!!'
exit
else
echo '===================================='
echo 'my.cnf configuration success!'
echo '===================================='
fi
if ! test -d "/usr/local/mysql/data"; then
mkdir -p /usr/local/mysql/data
fi
# 创建 /var/lib/mysql ⽬录,并修改权限
mkdir /var/lib/mysql
chmod 777 /var/lib/mysql
}
#安装 MYSQL
function mysql_install() {
dpkg -i $curdir/libaio1_0.3.110-5_amd64.deb > /dev/null
dpkg -i $curdir/libaio-dev_0.3.110-5_amd64.deb > /dev/null
pushd /usr/local/mysql
./bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data 2>&1 | tee $log
# 获取 root 初始密码
InitialPassword=$(tail -1 $log | awk '{print $NF}')
# 复制启动脚本到资源⽬录,并修改 basedir 和 datadir 为对应⽬录
cp ./support-files/mysql.server /etc/init.d/mysqld
sed -i '46s/basedir=/basedir=\/usr\/local\/mysql/g' /etc/init.d/mysqld
sed -i '47s/datadir=/datadir=\/usr\/local\/mysql\/data/g' /etc/init.d/mysqld
if [ $? -ne 0 ]; then
echo 'Failed to replace /etc/init.d/mysqld!!!'
exit
else
echo '===================================='
echo '/etc/init.d/mysqld success!'
echo '===================================='
fi
popd
# 设置MYSQL系统服务并开启⾃启
chmod +x /etc/init.d/mysqld
# 启动MYSQLD
/etc/init.d/mysqld restart
# 检查 MySQL 服务是否启动成功
netstat -ntlp | grep 3306
if [ $? -ne 0 ]; then
echo 'MySQL Boot failure!!!'
exit
else
echo '===================================='
echo 'start MySQL success!'
fi
# 登陆MYSQL,并执行 SQL 语句
#use mysql;
#update user set user.Host='%' where user.User='root';
/usr/local/mysql/bin/mysql -uroot -p"$InitialPassword" --connect-expired-password <<EOF alter user user() identified by "123456789"; flush privileges; exit EOF
if [ $? -ne 0 ]; then
echo 'fail to perform MySQL operation!!!'
exit
else
echo '===================================='
echo 'All operations were successful!!!'
echo '===================================='
fi
}
function main() {
deCompression
createMysqlGroup
mycnf
mysql_install
}
main
边栏推荐
猜你喜欢

On the exploitation of a horizontal ultra vires vulnerability

Double carbon in every direction: green demand and competition focus in the calculation from the east to the West

Matplotlib 学习笔记

Docker部署Mysql

MySQL到底怎么优化?
Some experience in database table structure design

冗余码题型--后面加0的区别

Apple zoom! It's done so well

Introduction to binary tree

EasyClick 运行代码片段出Null
随机推荐
ADG备库MRP0状态WAIT_FOR_GAP
June training (day 13) - two way linked list
36 krypton launched | built domestic actuarial forecasting engine and other products, and "Shenzhen light technology" completed three consecutive rounds of financing
Test redundancy code for error problem type solution - excerpt
Some experience in database table structure design
2022 coal mine water exploration and drainage special operation certificate examination question bank simulated examination platform operation
Review of last week's hot spots (6.6-6.12)
Docker deployment MySQL
go-zero微服务实战系列(三、API定义和表结构设计)
Questions and answers of the labor worker general basic (labor worker) work license in 2022
Programming principles
数据库学习笔记(第十五章)
Introduction to binary tree
d编译时生成唯一标识
2022年劳务员-通用基础(劳务员)上岗证题目及答案
文件夹数据同步工具Sync Folders Pro
Cynthia项目缺陷管理系统
SQL server cannot find user or group when creating windows login account
Codeforces Round #798 (Div. 2)ABCD
Chapter I Section I