CentOS7.2 automatically installs mysql

Source: Internet
Author: User
Tags install perl

CentOS7.2 automatically installs mysql

########################### Number of preemptible parts ########## #############

-- Every time MySQL is installed, it is laborious and time-consuming.

-- CentOS6.5 CentOS7.2 self-test successful

-- This is used to install MYSQL on your own. It's a cool job.

Install: Download The mysql.rar file and follow readme.txt.

############################# Terminator ######### #################

Or you can change it yourself.

Shell file:

[Java] view plaincopy
  1. #! /Bin/sh
  2. # Closing a process
  3. /Etc/init. d/mysqldstop
  4. Killallmysqld
  5. Pids = ($ (ps-ef | grepmysql | awk '{print $2 }'))
  6. For (I = 0; I <$ {# pids [@]}; I ++); do
  7. Echo "shut down the process: pid $ {pids [I]}"
  8. Kill-9 $ {pids [I]}
  9. Done
  10. # UninstallMariaDB
  11. Mariadb = ($ (rpm-qa | grep-iMariaDB ))
  12. For (I = 0; I <$ {# mariadb [@]}; I ++); do
  13. Echo "Old mariadb: $ {mariadb [I]}"
  14. Echo "delete ..."
  15. Yum-yremove $ {mariadb [I]}
  16. Done
  17. # Force uninstall to prevent residue
  18. Mariadb = ($ (rpm-qa | grep-iMariaDB ))
  19. For (I = 0; I <$ {# mariadb [@]}; I ++); do
  20. Echo "Old mariadb: $ {mariadb [I]}"
  21. Echo "Force Delete ..."
  22. Rpm-e -- nodeps $ {mariadb [I]}
  23. Rpm-e -- noscripts $ {mariadb [I]}
  24. Done
  25. # Uninstalloldmysql
  26. Old_mysql = ($ (rpm-qa | grep-imysql ))
  27. For (I = 0; I <$ {# old_mysql [@]}; I ++); do
  28. Echo "Old MYSQL: $ {old_mysql [I]}"
  29. Echo "delete ..."
  30. Yum-yremovejava $ {old_mysql [I]}
  31. Done
  32. # Removeoldmysqlfiles
  33. Old_mysql_file = ($ (find/-namemysql ))
  34. For (I = 0; I <$ {# old_mysql_file [@]}; I ++); do
  35. Echo "Old MYSQL file: $ {old_mysql_file [I]}"
  36. If [[$ {old_mysql_file [I]} = ~ "/Usr/mysql"]
  37. Then
  38. Continue
  39. Fi
  40. Echo "delete ..."
  41. Rm-rf $ {old_mysql_file [I]}
  42. Done
  43. # Removesettingfiles
  44. Rm-rf/var/log/mysqld. log
  45. Rm-rf/etc/my. cnf *
  46. Rm-rf/run/mysqld /*
  47. Rm-rf/usr/bin/mysql *
  48. # Findzipmysqlfile
  49. SrcPath = $ (find/usr/mysql-maxdepth1-typef | grepmysql *. tar)
  50. If [[$ srcPath = ~ "Mysql"]
  51. Then
  52. Echo "installation package: $ srcPath"
  53. Else
  54. Echo "Download mysql ..."
  55. Yum-yinstallwget
  56. Wgethttps: // response/
  57. SrcPath = $ (find/usr/mysql-maxdepth1-typef | grepmysql *. tar)
  58. Fi
  59. # Unzip
  60. Echo "decompress ..."
  61. Tarxvf $ srcPath
  62. # Install Dependencies
  63. Echo "Install perl-DBI ..."
  64. Yuminstall-yperl-DBI
  65. Echo "Install libaio ..."
  66. Yuminstall-ylibaio
  67. # Install
  68. Rpms = ($ (finding/usr/mysql-maxdepth1-typef | grepmysql-community ))
  69. For (r =$ {# rpms [@]}; r> 0; r --); do
  70. Echo "$ r"
  71. For (I = 0; I <$ {# rpms [@]}; I ++); do
  72. Echo ""
  73. Echo "installation: $ {rpms [I]}"
  74. Echo "Install ..."
  75. Rpm-ivh $ {rpms [I]}
  76. Done
  77. Done
  78. # Start startup
  79. Chkconfigmysqldon
  80. Echo ""
  81. Echo "after installation, initialization Settings"
  82. /Etc/init. d/mysqldstart
  83. TmpPwd = $ (grep 'temporarypassword'/var/log/mysqld. log | awk-F': ''{print $2 }')
  84. Echo "TempPasswordis $ tmpPwd"
  85. Echo "#1. Stop mysql Database"
  86. /Etc/init. d/mysqldstop
  87. Echo "#2. Start mysqld_safe"
  88. Mysqld_safe -- user = mysql -- skip-grant-tables -- skip-networking &
  89. For (I = 0; I <10; I ++); do
  90. Sleep4s
  91. Ps = ($ (ps-ef | grepmysqld_safe | awk '{print $1 }'))
  92. If [$ {# ps [@]}-gt1]; then
  93. Echo "mysqld_safestarted"
  94. Echo "#3. Use root to log on to the mysql database and set the password to" root ""
  95. Mysql-urootmysql <EOF
  96. /* Update the root password */
  97. UPDATEuserSETauthentication_string = PASSWORD ('root') whereUSER = 'root ';
  98. /* Refresh permission */
  99. FLUSHPRIVILEGES;
  100. EOF
  101. TmpPwd = "root"
  102. Break
  103. Else
  104. Echo "$ {I }..."
  105. Sleep1s
  106. If [$ {I}-ge5]; then
  107. Echo "mysqld_safe: notstarted"
  108. Break;
  109. Fi
  110. Fi
  111. Done
  112. Echo "restart mysql"
  113. /Etc/init. d/mysqldrestart
  114. # Write port = 3306 to the/etc/my. cnf File
  115. Echo "set port"
  116. Sed-I '/datadir =/I \ port = 3306'/etc/my. cnf
  117. Echo "successrestart ..."
  118. Servicemysqldrestart
  119. Echo "mysqlhasbeeninstalledandstarted"
  120. Echo ""
  121. Echo"
  122. Youprobablyneedtodooperationsasfollowsbyyourselfforsomesecurityreasons.
  123. /* Enter MYSQL */
  124. Mysql-uroot-p $ {tmpPwd}
  125. /* Change Password Length Policy */
  126. Setglobalvalidate_password_policy = 0;
  127. Setglobalvalidate_password_length = 0;
  128. /* Reset the password */
  129. Alteruser 'root' @ 'localhost' identifiedby 'root ';
  130. FLUSHPRIVILEGES;
  131. /* Set Internet access */
  132. Usemysql;
  133. Select 'host' fromuserwhereuser = 'root ';
  134. Updateusersethost = '%' whereuser = 'root ';
  135. FLUSHPRIVILEGES;
  136. "

1. Place it in/usr/mysql to run

2. Put the mysql file of mysql in/usr/mysql/

3. Set the initial password to root. Activate it as prompted by the installation.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.