奇怪的安装mysql脚本之一
groupadd mysql -g 27
useradd mysql -u 27 -g 27 -c "MySQL Server" -d /home/mysql -m
function代码
function install_mysql() { groupadd mysql useradd -s /sbin/nologin -M -g mysql mysql if [ -n "$1" ] ; then mysqlrootpwd=$1; else mysqlrootpwd=`openssl rand -base64 32| tr -dc _A-Z-a-z-0-9 | head -c12`; fi echo root $mysqlrootpwd ' | ' `date` >> /root/mysql.txt yum -y -q install mariadb mariadb-server galera ln -s /usr/lib/systemd/system/mariadb.service /usr/lib/systemd/system/mysql.service systemctl enable mariadb systemctl start mariadb mysqladmin -u root password $mysqlrootpwd setmyqlroot $mysqlrootpwd sed -i 's/skip-locking/skip-external-locking/g' /etc/my.cnf } function setmyqlroot() { if [ -n "$1" ] ; then mysqlrootpwd=$1; else mysqlrootpwd=`openssl rand -base64 32| tr -dc _A-Z-a-z-0-9 | head -c12`; echo root $mysqlrootpwd ' | ' `date` >> /root/mysql.txt ; fi mysql -uroot -p$mysqlrootpwd <<EOF UPDATE mysql.user SET Password=PASSWORD("$mysqlrootpwd") WHERE User='root'; DELETE FROM mysql.user WHERE User=''; DELETE FROM mysql.user WHERE User='root' AND Host NOT IN ('localhost', '127.0.0.1', '::1'); DROP DATABASE IF EXISTS test; DELETE FROM mysql.db WHERE Db='test' OR Db='test\\_%'; FLUSH PRIVILEGES; exit EOF }
执行安装
install_mysql()
mysql_install_db --user=mysql --datadir=/home/mysql --no-defaults &
mysqladmin -u root password $mysqlrootpwd