练习:MySQL 5.7.20二进制安装步骤
MySQL有三种安装方式:二进制安装;源码安装;RPM包安装。这里推荐使用二进制安装方式
cat mysql-install.sh
#!/bin/bash
#
#mysql 5.7.20 binary system install script
mysql_install_bs() {
cd $soft_dir
tar xf $mysql_bs_version -C /usr/local
mv /usr/local/${mysql_bs_version%.tar.gz} $mysql_prefix
groupadd mysql && useradd -s /sbin/nologin -M -m mysql mysql
mkdir -p /data/mysql
chmod -R mysql.mysql $mysql_prefix /data
echo "export PATH=$PATH:$mysql_prefix/bin" >>/etc/profile
rpm -e `rpm -qa|grep mariadb` --nodeps
yum -y install libaio-devel
}
-----------------------------------------------------------------------------------------
cat mysql_config.sh
#!/bin/bash
#config conf
config() {
#tengine
\cp $config_dir/nginx.conf $nginx_prefix/conf/nginx.conf
\cp $config_dir/index.php $nginx_prefix/html/index.php
\cp $php_prefix/etc/php-fpm.d/www.conf.default $php_prefix/etc/php-fpm.d/www.conf
$nginx_prefix/sbin/nginx
/etc/init.d/php-fpm start
#init mysql database 1:temp password
# mysqld --initialize --user=mysql --basedir=$mysql_prefix --datadir=/data/mysql
#init database 2:blank password
\rm -rf /data/mysql/*
mysqld --initialize-insecure --user=mysql --basedir=$mysql_prefix --datadir=/data/mysql
#mysql ver 5.6 init database:
# mysql_install_db --initialize-insecure --user=mysql --basedir=$mysql_prefix --datadir=/data/mysql
cat >>/etc/mysql.cnf<<-EOF
[mysqld]
user=mysql
basedir=/usr/local/mysql
datadir=/data/mysql
server_id=6
port=3306
socket=/tmp/mysql.sock
[mysql]
socket=/tmp/mysql.sock
prompt=3306 [\\d]>
EOF
#method 1:cp mysqld conf to init.d
# cp $mysql_prefix/support-files/mysql.server /etc/init.d/mysqld
cd $mysql_prefix/support-files && ./mysql.server start
##method 2:systemctl
cat >>/etc/systemd/system/mysqld.service<<-EOF
[Unit]
Description=MySQL Server
Documentation=man:mysqld(8)
Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target
[Install]
WantedBy=multi-user.target
[Service]
User=mysql
Group=mysql
ExecStart=/usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf
LimitNOFILE=5000
EOF
systemctl start mysqld.service
}
[root@Manager system]# ss -tnl |grep 3306
LISTEN 0 80 :::3306 :::*
总结:
1.MySQL5.7.20安装步骤与5.6有一些去区别,尽量使用生成空密码的方式
2.MySQL的配置文件以及systemd管理服务的配置文件