In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
This article introduces the knowledge of "MySQL automatic installation script sharing". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Environmental requirements: centos:6.8
MySQL:5.7.20
MySQL installation file name: mysql-5.7.20-linux-glibc2.12-x86_64.tar.gz
MySQL source file path: / usr/local/src
MYSQL script file: / usr/local/src/install_mysql.sh
1. The script is as follows:
# / bin/sh
# px 2017-11-29
# mysql install
# email:kitten-pan@163.com & 752684428
# version 2.0
# mysql-version mysql5.7.20
Source_path=/usr/local/src
Install_path=/usr/local/mysql
Install_name=mysql-5.7.20-linux-glibc2.12-x86_64
# # testing the local environment
Env_fun ()
{
Echo "= check the native environment, please wait..."
Username= `cat / etc/passwd | grep mysql | cut-c 1-5`
If ["$username" = "mysql"]; then
Echo "MySQL account is exits..."
Return 10
Else
Echo "mysql account is not exits,ready add..."
Groupadd mysql
Useradd-r-s / sbin/nologin-g mysql mysql-d / usr/local/mysql
Return 12
Fi
}
# # judging whether MySQL is installed
Check_fun ()
{
Rpm_name= `rpm-aq | grep mysql- server`
Echo $rpm_name
If [! $rpm_name]; then
Echo "begin check the source install,please wait for a moment..."
If [- d $install_path]; then
Echo "source install is exist,quit..."
Exit 0
Else
Echo "MySQL is not installed on this machine. I will install it for you later."
Install_fun
Op_fun
Fi
Else
Echo-n "rpm MySQL is already installed, delete it? [yes | no]"
Read select
If [$select = yes]; then
Rpm-e $rpm_name-- nodeps
Rm-rf / var/log/mysqld.log
Check_fun
Else
Exit 0
Fi
Fi
}
# install MySQL
Install_fun ()
{
Read-p "Input a mysql version:"-t 30 mysql_version
Read-p "Input a mysql port:"-t 30 mysql_port
Read-p "Input a mysql_server_id:"-t 30 mysql_server_id
Cd $source_path & & echo "decompressing, please waiting..."
Tar-zxvf ${install_name} .tar.gz & & mv $install_name $install_path
# # creating a data Directory
Mkdir-pv / data/mysqldata
# give MySQL account permission to MySQL directory
Cd / usr/local & & chown mysql.mysql mysql
Chown-R mysql.mysql / data/mysqldata
Cd $install_path & & bin/mysqld-- initialize-- user=mysql-- basedir=/usr/local/mysql-- datadir=/data/mysqldata
Cd support-files & & cp-rf mysql.server / etc/init.d/mysqld
Sed-I 's#datadir\ =\ / usr\ / local\ / mysql\ / data#\ datadir\ =\ / data\ / mysqldata#g' / etc/init.d/mysqld
Cat > / etc/my.cnf > / etc/profile
Echo 'export MYSQL_PS1= "(\ u@\ h:\ p) [\ d] >"' > > / etc/profile
Source / etc/profile
Service mysqld restart
}
Op_fun ()
{
Chmod 755 / etc/init.d/mysqld
Chkconfig-add mysqld
Chkconfig-level 345 mysqld on
}
Main () {
Echo "#"
Echo "# welcome to make install mysql with this script###"
Echo "# copyright 2013 by px###"
Echo "#"
Sleep 5
Env_fun
Re=$?
If [re = 10]; then
Check_fun
Else
Check_fun
Fi
}
Main
Exit 0
2. Execute the automatic installation script
You need to fill in the MySQL version information, port information, serverid information, etc.
Click (here) to collapse or open
Sh install_mysql.sh
# =
# welcome to make install mysql with this script###
# copyright 2013 by px###
# =
= check the local environment, please wait...
Mysql account is not exits,ready add...
Begin check the source install,please wait for a moment...
MySQL is not installed on this machine. I will install it for you later.
Input a mysql version:5.7.20
Input a mysql port:3309
Input a mysql_server_id:1
Decompressing, please waiting...
3. Start after automatic installation
# service mysqld restart
MySQL server PID file could not be found! [FAILED]
Starting MySQL. [OK]
4. Log in to MySQL to change your password
Click (here) to collapse or open
[root@ct562 mysqldata] # mysql-uroot-p
Enter password:
Welcome to the MySQL monitor. Commands end with; or\ g.
Your MySQL connection id is 3
Server version: 5.7.20-log
Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
Affiliates. Other names may be trademarks of their respective
Owners.
Type 'help;' or'\ h' for help. Type'\ c'to clear the current input statement.
(root@localhost:mysql.sock) [(none)] >
(root@localhost:mysql.sock) [(none)] >
(root@localhost:mysql.sock) [(none)] >
(root@localhost:mysql.sock) [(none)] >
(root@localhost:mysql.sock) [(none)] >
(root@localhost:mysql.sock) [(none)] > set password for root@'localhost' = PASSWORD ('sysdba@321')
This is the end of "MySQL automatic installation script sharing". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.