1、Mysql自动安装5.7Shell脚本

1、Mysql自动安装5.7Shell脚本,第1张

如果您觉得文本对您有帮助,请打赏,谢谢。

新建执行脚本:mysql_install.sh,并添加执行权限

#!/bin/bash

#zhouyihua V0.1 2021.07.08

#For centos 7.0

# add DNS

echo "----------  Add DNS  --------"

echo "nameserver 8.8.8.8" >>/etc/resolv.conf

#stop firewall

systemctl stop firewalld

if [ $? -ne 0 ]then

    echo "Firewall stop failed"

else

    echo "Firewall stop success"

fi

#download mysql yum source

wget https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm

#install mysql yum source

rpm -ivh mysql80-community-release-el7-3.noarch.rpm

#enable 5.7

sed -i '21s/enabled=0/enabled=1/g' /etc/yum.repos.d/mysql-community.repo

sed -i '21s/enabled=0/enabled=1/g' /etc/yum.repos.d/mysql-community.repo

#disable 8.0

sed -i '28s/enabled=1/enabled=0/g' /etc/yum.repos.d/mysql-community.repo

#install mysql

yum -y remove mariadb-libs

yum install -y mysql-community-server

#config mysql

echo "-----------  Config my.cnf  ----------"

sed -i '/\[mysqld\]/a\lower_case_table_names=1' /etc/my.cnf

sed -i '/\[mysqld\]/a\skip-grant-tables' /etc/my.cnf

#start mysql

echo "----------  Starting mysql service  ----------"

systemctl start mysqld.service

mysql -uroot -p123456  <<EOF

    use mysql

    update mysql.user set authentication_string=password('Oracle1234!@#$') where user='root'

EOF

echo "----------  Annotation skip grant tables in my.cnf    ----------"

sed -i 's/skip-grant-tables/\#skip-grant-tables/g' /etc/my.cnf

echo "----------  Restart mysql service  ----------"

systemctl restart mysqld.service

echo "----------  Grant all privileges  ----------"

mysql -uroot -p'Oracle1234!@#$'    --connect-expired-password -e "alter user 'root'@'localhost' identified by 'Oracle1234!@#$'"

mysql -u root -p'Oracle1234!@#$'  <<EOF

    use mysql

    GRANT ALL PRIVILEGES ON *.* TO 'iam'@'%' IDENTIFIED BY 'Oracle1234!@#$'

EOF

1.1 编译安装

# groupadd mysql

# useradd -g mysql -d /usr/local/lib/mysql -s /sbin/nologin mysql

# tar zxvf mysql-x.x.x

# cd mysql-x.x.x

# ./configure --prefix=/usr/local/lib/mysql --localstatedir=/usr/local/lib/mysql/data --with-charset=utf8 --with-extra-charsets=all

# make

# make install

# cp support-files/my-medium.cnf /etc/my.cnf

# cd /usr/local/lib/mysql

# mkdir data

# bin/mysql_install_db --user=mysql

# chown -R root .

# chown -R mysql data

# chgrp -R mysql .

# echo "/usr/local/lib/mysql/bin/mysqld_safe &" >>/etc/rc.local

# /usr/local/lib/mysql/bin/mysqld_safe --user=mysql &

1.2 进入mysql的DBMS

# /usr/local/lib/mysql/bin/mysql -u root -p

enter password: <Enter>

*注:默认mysql的root用户口令为空

1.3 mysql数据在页面显示为中文乱码的问题

--with-extra-charsets=all是解决中文乱码的关键参数,它的作用是安装额外的字符集,其中即包括gbk等中文字符集。在创建数据库时手工指定字符集为gbk,这样就可以保证同样使用gbk字符集的HTML页面正常地显示中文了:

create database <db_name>default character set gbk collate gbk_chinese_ci

2. 安装Apache

===============

2.1 编译安装

# tar zxvf httpd-x.x.x.tar.gz

# cd httpd-x.x.x

# ./configure --prefix=/usr/local/lib/apache --enable-so --enable-mods-shared=all --enable-rewrite=shared --enable-speling=shared

# make

# make install

2.2 apache启动停止命令

# /usr/local/lib/apache/bin/apachectl start

# /usr/local/lib/apache/bin/apachectl stop

# /usr/local/lib/apache/bin/apachectl restart

2.3 自动运行

# echo "/usr/local/lib/apache/bin/apachectl start" >>/etc/rc.local

2.4 apache启动时可能出现的错误

[Fri Dec 30 09:35:01 2005] [warn] (2)No such file or directory: Failed to enable the 'httpready' Accept Filter

写这个mysql目的原来是在做web项目的一键部署安装,其实就是exe自动运行安装。脚本注释内容较少 为什呢

支持功能:

改密,执行sql文件,多mysql运行等等。

sql文件内容不提供了 想知道 给我点赞呗 点完我再发


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/6194851.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-03-17
下一篇 2023-03-17

发表评论

登录后才能评论

评论列表(0条)

保存