小言_互联网的博客

shell_一键部署Mysql脚本

247人阅读  评论(0)

一.一键部署Mysql

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


#!/bin/bash

systemctl stop firewalld
setenforce 0

yum -y install \
gcc \
gcc-c++ \
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"


注意:启动脚本一定要source启动脚本

  • sh 启动脚本,source /etc/profile 重载刷新配置文件命令会不生效。需要装完,
  • 再启动执行source /etc/profile 才生效。

解释为啥source/ect/profile不生效原因



可授权远程登录

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

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


转载:https://blog.csdn.net/Wsxyi/article/details/115473591
查看评论
* 以上用户言论只代表其个人观点,不代表本网站的观点或立场