Ubuntu Server 21.04 Install one key Generic mysql 8.0.26

Posted CIAS

tags:

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

        

前言

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-8.0.26_install.sh
#!/bin/sh
# -*- coding: utf-8 -*-
# Author: CIASM 
# Date: 2021/12/23
 
#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-8.0/
MYSQL_FILE=mysql-8.0.26-linux-glibc2.12-x86_64.tar.xz
MYSQL_PREFIX=/usr/local/mysql
MYSQL_glibc=mysql-8.0.26-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
default-character-set=utf8

[mysqld]
datadir = /data/mysql_data3306
socket = /data/mysql_data3306/mysql.sock
log-error = /var/log/mysql_3306.log
port = 3306
character-set-server=utf8
log_timestamps = SYSTEM
default-time_zone = '+8:00'
log_bin_trust_function_creators = on
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
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"
sleep 3
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'; FLUSH PRIVILEGES;"

#cofig Mysql alter database
mysql -uroot -pCiasm@123 -e "use mysql; update user set host = '%' where user = 'root'; FLUSH PRIVILEGES; ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'Ciasm@123';"

 
#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-8.0.26_install.sh

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

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