CentOS 7.5一键脚本安装MySQL

CentOS 7.5一键脚本安装MySQL

mysql 版本 : mysql-5.7.27-linux-glibc2.12-x86_64.tar.gz
shell脚本: auto_install_mysql.sh

脚本写权限

[root@localhost /]# chmod +x auto_install_mysql.sh
[root@localhost /]# yum install -y dos2unix.x86_64
[root@localhost /]# dos2unix auto_install_mysql.sh
dos2unix: converting file auto_install_mysql.sh to Unix format …
写入脚本
[root@localhost /]# sh auto_install_mysql.sh ##以下为脚本代码

#!/bin/bash
export LANG=en_US.UTF-8
 
INSTALL_PATH=$(pwd)
echo "当前目录:"+${INSTALL_PATH}
 
echo "删除mysql相关配置文件并copy my.cnf到etc目录"
rm -rf /etc/my.cnf
rm -rf /etc/init.d/mysql
cp my.cnf /etc/my.cnf
 
echo "创建mysql用户组和用户"
groupadd mysql
useradd -g mysql mysql
 
echo "解压.tar.gz到指定文件夹下 /usr/local/mysql"
tar -vxzf mysql-5.7.27-linux-glibc2.12-x86_64.tar.gz
mv mysql-5.7.27-linux-glibc2.12-x86_64/ /usr/local/mysql/
 
echo "更改usr/local/mysql所属的组和用户"
cd /usr/local
USR_LOCAL=$(pwd)
 
chown -R mysql mysql/
chgrp -R mysql mysql/
 
cd mysql/
echo "创建mysql数据目录data并设置目录权限"+$(pwd)
mkdir data
chown -R mysql:mysql data
 
echo "创建my.cnf配置文件"
cat >/etc/my.cnf<<EOF
[mysql]
# 设置mysql客户端默认字符集
default-character-set=utf8 
[mysqld]
skip-name-resolve
#设置3306端口
port = 3306 
# 设置mysql的安装目录
basedir=/usr/local/mysql
# 设置mysql数据库的数据的存放目录
datadir=/usr/local/mysql/data
# 允许最大连接数
max_connections=200
# 服务端使用的字符集默认为8比特编码的latin1字符集
character-set-server=utf8
# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB 
lower_case_table_names=1
max_allowed_packet=16M
EOF

echo "设置mysql权限并初始化mysql"
cp ./support-files/mysql.server /etc/init.d/mysqld
chown 777 /etc/my.cnf
chmod a+x /etc/init.d/mysqld
/usr/local/mysql/bin/mysqld --initialize  --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/
 
echo "修改mysql环境变量>>>>>>>>>>>"
echo 'export PATH=$PATH:/usr/local/mysql/bin' >> /etc/profile
sleep 2
source /etc/profile
 
if [ $? -eq 0 ]; then
     echo "配置mysql环境变量成功!"
else
     echo "配置mysql环境变量失败!"
fi
 
#yum install -y psmisc
#killall mysqld
 
service mysqld restart
sleep 5
echo "mysql启动成功!"

echo "通过mysql -uroot -p 操作"
ln -s /usr/local/mysql/bin/mysql /usr/bin

echo "设置mysql开机自启!"
chmod +x /etc/rc.d/init.d/mysqld
chkconfig --add mysqld
chkconfig --level 35 mysqld
 
echo "mysql重设后启动成功!!!!!!"

[root@localhost /]# sh auto_install_mysql.sh ##此处以下为安装过程内容
当前目录:+/
删除mysql相关配置文件并copy my.cnf到etc目录
cp: cannot stat ‘my.cnf’: No such file or directory
创建mysql用户组和用户
解压.tar.gz到指定文件夹下 /usr/local/mysql
mysql-5.7.27-linux-glibc2.12-x86_64/bin/myisam_ftdump
mysql-5.7.27-linux-glibc2.12-x86_64/bin/myisamchk
mysql-5.7.27-linux-glibc2.12-x86_64/bin/myisamlog



2021-07-12T08:52:13.159791Z 1 [Note] A temporary password is generated for root@localhost: IrlOJCbHw1>j ####MySQL登录密码
修改mysql环境变量>>>>>>>>>>>
配置mysql环境变量成功!
ERROR! MySQL server PID file could not be found!
Starting MySQL.Logging to ‘/usr/local/mysql/data/localhost.localdomain.err’.
SUCCESS!
mysql启动成功!
通过mysql -uroot -p 操作
设置mysql开机自启!
only one runlevel may be specified for a chkconfig query
mysql重设后启动成功!!!

查看MySQL是否启动

[root@localhost /]# ps -ef|grep mysql

查看监听端口

[root@localhost /]# netstat -lntp | grep mysqld
tcp6 0 0 :::3306 ::😗 LISTEN 2218mysqld

更改mysql数据库密码

[root@localhost ~]# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.27

Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> set password for root@localhost = password('Admin@1234');
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> flush privileges; 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

机灵的小小子

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值