mysql5.5.sh 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #!/bin/bash
  2. MySQLRoot="/usr/local/mysql"
  3. apt install -y libaio1 libncurses5 wget
  4. systemctl stop mysql >/dev/null 2>&1
  5. bash /etc/init.d/mysql.server stop >/dev/null 2>&1
  6. rm -rf /var/lib/mysql
  7. rm -rf /etc/mysql
  8. rm -rf /etc/my.cnf
  9. rm -rf /etc/init.d/mysql.server
  10. rm -rf /usr/local/bin/mysql
  11. rm -rf "$MySQLRoot"
  12. groupadd mysql
  13. useradd -g mysql mysql
  14. rm -rf /usr/local/mysql
  15. mkdir -p /usr/local/mysql
  16. wget -qO- https://downloads.mysql.com/archives/get/p/23/file/mysql-5.5.62-linux-glibc2.12-x86_64.tar.gz |tar -zxv --strip-components=1 -C "$MySQLRoot"
  17. chown -R mysql:mysql "$MySQLRoot"
  18. cd "$MySQLRoot"
  19. "$MySQLRoot/scripts/mysql_install_db" --user=mysql
  20. chown -R root:root "$MySQLRoot"
  21. chown -R mysql:mysql "$MySQLRoot/data"
  22. cp -rf "$MySQLRoot/support-files/mysql.server" /etc/init.d/mysql.server
  23. cp -rf "$MySQLRoot/support-files/my-medium.cnf" /etc/my.cnf
  24. sed -i '/^bind-address/d' /etc/my.cnf
  25. sed -i 's/\[mysqld\]/\[mysqld\]\nbind-address = 127.0.0.1/' /etc/my.cnf
  26. "$MySQLRoot/bin/mysqld_safe" --user=mysql >/dev/null &
  27. sleep 10
  28. "$MySQLRoot/bin/mysqladmin" -u root password ""
  29. ln -sf "$MySQLRoot/bin/mysql" /usr/local/bin/mysql
  30. update-rc.d -f mysql.server remove
  31. update-rc.d -f mysql.server defaults