Ubuntu Server 21.04 Install one key Generic mysql 5.7.35

Posted CIAS

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Ubuntu Server 21.04 Install one key Generic mysql 5.7.35相关的知识,希望对你有一定的参考价值。

       

前言

mysql 是最流行的关系型数据库管理系统,在 WEB 应用方面 MySQL 是最好的 RDBMS(Relational Database Management System:关系数据库管理系统)应用软件之一。

系统下载安装

ubuntu  系统安装&下载mysql 下载Mysql 管理Linux MobaXterm 远程连接工具
downloaddownloaddownloaddownload

 切换sh为bash 

dpkg-reconfigure dash
  •  输入NO

  • 查看切换结果,结果/bin/sh -> bash切换成功

ls -al /bin/sh

安装 Mysql

  • 创建一键安装脚本

  • 用户名root
  • 密码Ciasm@123
vim /mysql-5.7.35_install.sh
#!/bin/sh
# -*- coding: utf-8 -*-
# Author: CIASM 
# Date: 2021/12/09

#Define data path variables
data_downloads=/data/downloads

#Define MYSQL path variables
echo "Define MYSQL path variables"
sleep 3
MYSQL_URL=https://cdn.mysql.com/archives/mysql-5.7/
MYSQL_FILE=mysql-5.7.35-linux-glibc2.12-x86_64.tar.gz
MYSQL_PREFIX=/usr/local/mysql
MYSQL_glibc=mysql-5.7.35-linux-glibc2.12-x86_64

mysql_package ()
echo "Installing dependency packages"
sleep 3
apt install libaio1 libaio-dev libncurses5 firewalld wget curl net-tools vim -y


install_mysql ()
if [ ! -d $MYSQL_PREFIX ];then
mysql_package
timedatectl set-timezone Asia/Shanghai
mkdir -p $data_downloads
wget -N -P $data_downloads $MYSQL_URL/$MYSQL_FILE
tar -xf $data_downloads/$MYSQL_FILE -C $data_downloads
 if [ $? -eq 0 ];then 
   mv  $data_downloads/$MYSQL_glibc /usr/local/mysql
   mysql_config
		echo -e "\\033[32mThe MYSQL Install Success...\\033[0m"
   else
		echo -e "\\033[31mThe MYSQL Install Failed...\\033[0m"
		exit 1
fi
   else
	echo -e "\\033[31mThe MYSQL already Install...\\033[0m"
	exit 1 
fi  



mysql_config ()
echo "mysql config"
sleep 3
useradd mysql -r -s /sbin/nologin
mkdir -p /data/mysql_data3306
chown root.mysql -R /usr/local/mysql

cat >>/etc/my.cnf<<EOF
[client]    
port = 3306
socket  = /data/mysql_data3306/mysql.sock

[mysqld]
datadir = /data/mysql_data3306
socket = /data/mysql_data3306/mysql.sock
log-error = /var/log/mysql_3306.log
port = 3306
user = mysql
log-bin=mysql-bin
server-id=1
performance_schema = off
innodb_buffer_pool_size = 32M
bind_address = 0.0.0.0
skip-name-resolve = 0
lower_case_table_names=1
character_set_server=utf8
log_timestamps = SYSTEM
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
max_connections=1000
innodb_file_per_table=1
innodb_file_format=Barracuda
log_bin_trust_function_creators=on
EOF

#Creating log output
echo "Creating log output"
sleep 3
touch /var/log/mysql_3306.log && chown -R mysql:mysql /var/log && chmod 755 /var/log/mysql*

echo "initialized database"
sleep 3
#Initialize each instance: After initialization, the password will be generated in the log. Remember to save it and use it later.
/usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql_data3306  --log_error=/var/log/mysql_3306.log

#Open SSL connections for each instance
/usr/local/mysql/bin/mysql_ssl_rsa_setup --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql_data3306 --log_error=/var/log/mysql_3306.log

echo "Configure the database startup service"
sleep 3
#Copying server the Startup Script
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld

#Creating a service script
cat >>/lib/systemd/system/mysqld.service<<EOF
[Unit]

Description=mysqld
After=network.target

[Service]
Type=forking
ExecStart=/etc/init.d/mysqld start
ExecReload=/etc/init.d/mysqld restart
ExecStop=/etc/init.d/mysqld stop

PrivateTmp=true

[Install]
WantedBy=multi-user.target
EOF

#start mysql
echo "start mysql"
sleep 3
systemctl daemon-reload  &&  systemctl enable --now mysqld

#Mysql environment variable
echo "Mysql environment variable"
sleep 3
sed -i '$aexport MYSQL_HOME=/usr/local/mysql' /etc/profile
sed -i '$aexport PATH=$MYSQL_HOME/bin:$PATH' /etc/profile
sed -i '$aexport PATH=$PATH:/usr/local/mysql/bin' /etc/profile 

echo "limits config"
sleep 3
cat >>/etc/security/limits.conf<<EOF
* soft nproc 65535
* hard nproc 65535
* soft nofile 65535
* hard nofile 65535
EOF

#source Refreshing environment variables
source /etc/profile

#system Maximum config
echo "system Maximum number of connections"
echo "fs.file-max=65535" >> /etc/sysctl.conf

#Resetting the Default Password
echo "mysql initialize default password"
sleep 3
mysql -S /data/mysql_data3306/mysql.sock -p`cat /var/log/mysql_3306.log | grep 'password is generated' | awk 'print $NF'` --connect-expired-password -e "alter user root@localhost identified by 'Ciasm@123'; GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'Ciasm' WITH GRANT OPTION; FLUSH PRIVILEGES;"

#firewall config
echo "config"
sleep 3
systemctl enable --now firewalld
firewall-cmd --zone=public --add-port=3306/tcp --permanent && firewall-cmd --reload 

#Delete mysql the downloaded installation package
echo "Delete mysql the downloaded installation package"
sleep 3
rm -rf $data_downloads/MYSQL_FILE



main ()
install_mysql


main
  • 执行一键安装

sh /mysql-5.7.35_install.sh

以上是关于Ubuntu Server 21.04 Install one key Generic mysql 5.7.35的主要内容,如果未能解决你的问题,请参考以下文章

Ubuntu Server 21.04 Install ansible

Ubuntu Server 21.04 Install ansible

Ubuntu Server 21.04 Install ansible

Ubuntu Server 21.04 Install one key Generic mysql 8.0.26

Ubuntu Server 21.04 Install Cockpit

Ubuntu Server 21.04 Install Cockpit