2、Mysql自动安装8.0Shell脚本

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

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

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

#!/bin/bash

#zhouyihua V0.1 2021.07.08

#For centos 7.0 &8.0

#v 0.2

# 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 module disable 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 user set authentication_string='' where user='root'

    flush privileges

    ALTER user 'root'@'localhost' IDENTIFIED BY '?CZJh8JWxvH';

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

    CREATE USER 'maxkey'@'%' IDENTIFIED BY 'Oracle1234!@#$'

    GRANT ALL ON *.* TO 'maxkey'@'%'

EOF

参考:

先设置grant_skip_tables

  1.  use mysql

  2. update user set authentication_string='' where user='root'     如果这个字段有值,先置为空

  3. flush privileges    刷新权限表

  4.ALTER user 'root'@'localhost' IDENTIFIED BY 'Tianya1234'    修改root 密码

参考:https://blog.csdn.net/qq_27820551/article/details/101488430

默认mysql是安装在/var/lib/mysql目录下,但是一般只有15G空间,令人至疯,所以装完必须迁移

cd /homemkdir data

mysqladmin -u root -p shutdown

[root@test1 mysql]# cp /usr/share/mysql/my-medium.cnf /etc/my.cnf

最后,需要修改MySQL启动脚本/etc/init.d/mysqld,把其中datadir=/var/lib/mysql一行中,等号右边的路径改成你现在的实际存放路径:home/data/mysql。

[root@test1 etc]# vi /etc/init.d/mysql#datadir=/var/lib/mysql(注释此行)datadir=/home/data/mysql (加上此行)

如果是CentOS还要改 /usr/bin/mysqld_safe 相关文件位置;

最后 做一个mysql.sock 链接:

in -s /home/data/mysql/mysql.sock /var/lib/mysql/mysql.sock

7、重新启动MySQL服务

/etc/init.d/mysql start或者service mysql restart

8、修改整个目录权限

chown -R mysql:mysql /home/data/mysql/

chmod -R 777 /home/data/mysql/*

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

支持功能:

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

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


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

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

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

发表评论

登录后才能评论

评论列表(0条)

保存