• 微信公众号:美女很有趣。 工作之余,放松一下,关注即送10G+美女照片!

shell_一键部署Mysql脚本

互联网 diligentman 1周前 (04-08) 5次浏览

Mysql一键部署脚本

  • 一.一键部署Mysql
    • 1.将安装Mysql所需软件包传到/opt目录下
      • 可授权远程登录

一.一键部署Mysql

1.将安装Mysql所需软件包传到/opt目录下

shell_一键部署Mysql脚本


#!/bin/bash

systemctl stop firewalld
setenforce 0

yum -y install 
ncurses 
ncurses-devel 
bison 
cmake

useradd -M -s /sbin/nologin  mysql

cd /opt
tar zxvf mysql-boost-5.7.20.tar.gz

cd /opt/mysql-5.7.20/
cmake 
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql 
-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock 
-DSYSCONFDIR=/etc 
-DSYSTEMD_PID_DIR=/usr/local/mysql 
-DDEFAULT_CHARSET=utf8  
-DDEFAULT_COLLATION=utf8_general_ci 
-DWITH_EXTRA_CHARSETS=all 
-DWITH_INNOBASE_STORAGE_ENGINE=1 
-DWITH_ARCHIVE_STORAGE_ENGINE=1 
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 
-DWITH_PERFSCHEMA_STORAGE_ENGINE=1 
-DMYSQL_DATADIR=/usr/local/mysql/data 
-DWITH_BOOST=boost 
-DWITH_SYSTEMD=1

make && make install


echo '[client]
port = 3306
socket=/usr/local/mysql/mysql.sock

[mysqld]
user = mysql
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
port = 3306
character-set-server=utf8
pid-file = /usr/local/mysql/mysqld.pid
socket=/usr/local/mysql/mysql.sock
bind-address = 0.0.0.0
skip-name-resolve
max_connections=2048
default-storage-engine=INNODB
max_allowed_packet=16M
server-id = 1

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_AUTO_VALUE_ON_ZERO,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,PIPES_AS_CONCAT,ANSI_QUOTES' > /etc/my.cnf

chown -R mysql:mysql /usr/local/mysql/
chown mysql:mysql /etc/my.cnf

echo 'export PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH' >> /etc/profile	
source /etc/profile



cd /usr/local/mysql/bin/
mysqld 
--initialize-insecure 
--user=mysql 
--basedir=/usr/local/mysql 
--datadir=/usr/local/mysql/data

cd /usr/local/mysql/bin/
cp /usr/local/mysql/usr/lib/systemd/system/mysqld.service /usr/lib/systemd/system/

systemctl daemon-reload
systemctl start mysqld.service
systemctl enable mysqld
netstat -anpt | grep 3306


if [ $? -eq 0 ];then
        echo "Mysql安装成功!"
else
        echo 启动失败
        exit 1
fi

read -p "输入登录Mysql密码" c
mysqladmin -u root -p password "$c"


shell_一键部署Mysql脚本

shell_一键部署Mysql脚本
shell_一键部署Mysql脚本
shell_一键部署Mysql脚本

可授权远程登录

mysql -u root -p123456
grant all privileges on *.* to 'root'@'%' identified by '123456';
#授予root用户可以在所有终端远程登录,使用的密码是123456,并对所有数据库和所有表有操作权限

show databases;			#查看当前已有的数据库

shell_一键部署Mysql脚本


程序员灯塔
转载请注明原文链接:shell_一键部署Mysql脚本
喜欢 (0)