当前位置:网站首页>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
边栏推荐
- Oracle custom data type question
- 文件夹数据同步工具Sync Folders Pro
- 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
- Experience of electric competition - program-controlled wind pendulum
- 2022 coal mine water exploration and drainage special operation certificate examination question bank simulated examination platform operation
- Implementation of fruit mall wholesale platform based on SSM
- Brief introduction to memory structure of virtual machine
- Similarities and differences between decoration mode and agency mode
- 2022煤矿探放水特种作业证考试题库模拟考试平台操作
猜你喜欢

数据库学习笔记(第十六章)

什么是400G以太网?

On the exploitation of a horizontal ultra vires vulnerability

IDEA 续命插件

Idea remote debugging jar submitted by spark submit

Experience of electric competition - program-controlled wind pendulum

China SaaS industry panorama

Install Kubernetes 1.24

Sunyuchen, head of Grenada delegation, attended the WTO MC12 and emphasized the development of digital economy

首个Laravel工作流引擎发布 V1.0正式版
随机推荐
周末赠书:Power BI数据可视化实战
Talk about MySQL indexing mechanism
【云享新鲜】社区周刊·Vol.66-华为伙伴暨开发者大会2022精彩议程公布
记几次略有意思的 XSS 漏洞发现
Thingsboard tutorial (20): filtering telemetry data using regular chains
了解RPC和REST
MySQL transaction isolation level and mvcc
[bearing fault decomposition] ITD bearing fault signal decomposition based on MATLAB [including Matlab source code 1871]
Similarities and differences between decoration mode and agency mode
Modification of string class object
About the problem of database: it can't be found after repeated inspection
go-zero微服务实战系列(三、API定义和表结构设计)
On the exploitation of a horizontal ultra vires vulnerability
一文读懂pgstat【这次高斯不是数学家】
Actual combat simulation │ real time error alarm of enterprise wechat robot
2022 tailings recurrent training question bank and simulated examination
Docker deployment MySQL
Software testing often asks, do you really build a testing environment?
Actual combat simulation │ real time error alarm of enterprise wechat robot
ADG备库MRP0状态WAIT_FOR_GAP