linux mysql一键部署脚本

base=$(pwd)
#cd /usr/local
rm -rf `find / -name mysql`
rm -rf /etc/my.cnf.d
rm -rf /etc/systemd/system/mysqld.service
tar -xzvf mysql-5.7.36-linux-glibc2.12-x86_64.tar.gz 
mv mysql-5.7.36-linux-glibc2.12-x86_64 mysql
mkdir -p $base/mysql/data/
chown -R mysql:mysql mysql
rm /etc/my.cnf
cat << EOG > /etc/my.cnf
[client]
port = 3306
socket = /tmp/mysql.sock
[mysqld]
init-connect='SET NAMES utf8'
basedir=$base/mysql
datadir=$base/mysql/data
socket=/tmp/mysql.sock
max_connections=50
character-set-server=utf8
default-storage-engine=INNODB
lower_case_table_names=1
EOG
chmod +x $base/mysql/bin/*
cd $base/mysql/bin
$base/mysql/bin/mysqld --initialize-insecure --user=mysql  --basedir=$base/mysql --datadir=$base/mysql/data
ln -s  $base/mysql/bin/mysql  /usr/bin
chown -R root:root $base/mysql/
chown -R mysql:mysql $base/mysql/data/
$base/mysql/support-files/mysql.server start
mysql -u root -p
show databases;
alter user 'root'@'localhost' identified by 'test_db';
create database test_db;
exit;
mysql -u root -ptest_db -D test_db <$base/test_db.sql

你可能感兴趣的:(linux,mysql,运维)