CentOS6.7 using a non-root user (normal user) compile and install the MySQL database and implement the MySQL database service random auto-start using the Shell Script timed task mode

Source: Internet
Author: User
Tags chmod install openssl openssl centos server disk usage

CentOS6.7 using a non-root user (normal user) compile and install the MySQL database and implement the MySQL database service random auto-start using the Shell Script timed task mode
1. About MySQL?
MySQL is a relational database management system developed by the Swedish MySQL AB company, currently owned by Oracle Corporation. MySQL is an associated database management system that keeps data in separate tables rather than putting all of the data in a large warehouse, which increases speed and increases flexibility.
Characteristics:
MySQL is open source, so you don't have to pay an extra fee.
MySQL supports a large database. You can handle large databases that have thousands records.
MySQL uses the standard SQL data language form.
MySQL can be allowed on multiple systems and is supported in multiple languages. These programming languages include C, C + +, Python, Java, Perl, PHP, Eiffel, Ruby, and Tcl.
MySQL has good support for PHP, which is currently the most popular web development language.
MySQL support large database, support 50 million records of Data Warehouse, 32-bit system table file maximum support 4gb,64 bit system to support the largest table file is 8TB.
MySQL can be customized, using the GPL protocol, you can modify the source code to develop their own MySQL system.
2. About compiling and installing?
Compile: Change the source code to a machine executable code file.
Install: The executable file is installed in the operating system before it can be used.
3. Install the dependent packages (tools and libraries) required to compile the code
Installing the Development Kit
Need to note that these are commonly used by the package, in order to prevent error, install more points, if you want to know what each tool package is what the specific thing, please ask the mother will know I here because of time for the problem is not one for everyone to introduce.
Here the CMake tool we can also use the compiled way to install, if interested please go to my csdn download: http://download.csdn.net/detail/xushouwei/9599540
Yum-y Groupinstall "Development Tools"
Yum-y Install openssl* zlib* pcre* ncurses* make cmake vsftpd lrzsz gcc gcc-c++ gcc-g77 flex bison* autoconf automake bzi P2-devel zlib-devel ncurses-devel libjpeg-devel libpng-devel libtiff-devel freetype-devel pam-devel openssl-devel Libxml2-devel gettext-devel pcre-devel net-snmp-devel curl-devel perl-dbi vixie-cron crontabs wget
1 is shown below:

4. Check if MySQL server is installed and uninstalled
Check if MySQL is installed
Rpm-qa|grep MySQL
2 is shown below:

Force the uninstallation of existing MySQL and view
RPM-E--nodeps mysql-libs-5.1.73-5.el6_6.x86_64
Rpm-qa|grep MySQL
3 is shown below:

At this point, we have compiled and installed MySQL pre-work is ready!
5. Use the root user to create a new normal user (non-root user) and view user information
Groupadd Formal
Useradd-g formal-m Formal
ID Formal
4 is shown below:

6. Upload/download MySQL source package
Get the MySQL source installation package in one way:
Download directly to MySQL website
: http://dev.mysql.com/downloads/mysql/5.5.html

5 is shown below:

Get the MySQL source installation package in one way:
Download directly from the network using the wget command
Wget Source Package Address

Because I have prepared the source package in advance, I use the first way to get it. If necessary, you can go to my csdn. Download: http://download.csdn.net/download/xushouwei/9599890
7. Switch the normal user formal, go to the/home/formal directory, create a new bak and MySQL directory in the/home/formal directory
Su-formal
Cd/home/formal
mkdir Bak MySQL
6 is shown below:

8. Go to the Bak directory and upload the source package.
CD bak
Rz
7 is shown below:

9. Unzip the mysql-5.5.45.tar.gz and go to the mysql-5.5.45 directory
TAR-ZXVF mysql-5.5.45.tar.gz
CD mysql-5.5.45
8 is shown below:

7. Compile process Check (mysql5.6 version above needs to install with CMake, this is necessary, other software can also use CMake installation, but the premise of using CMake installation is that there is no CMakeLists.txt this file under the source package, some words can use cmake.)
Compile the time must pay attention to have no space, otherwise will error.
CMake. -dcmake_install_prefix=/home/formal/mysql-dmysql_unix_addr=/home/formal/mysql/mysql_6603.sock-ddefault_charset =utf8-ddefault_collation=utf8_general_ci-dwith_myisam_storage_engine=1-dwith_innobase_storage_engine=1-dwith_ Memory_storage_engine=1-dwith_readline=1-denabled_local_infile=1-dmysql_datadir=/home/formal/mysql/data-dmysql _user=formal-dmysql_tcp_port=6603-dwithout_partition_storage_engine=1
9 is shown below:

Check that the compilation process checks whether the previous task succeeded successfully, 0 indicates success, and the other identity fails.
10 is shown below:

Common compilation parameters, can refer to the following table, more parameters, please find degrees Niang. (Note: The directory in the parameter and the port depends on the individual situation)
11 is shown below:

8. Compile, install (this process will take a while, please wait patiently)
Make && make install
12 is shown below:

Check that the compilation, installation, and success of previous tasks succeeded, 0 indicates success, and other identities fail.
13 is shown below:

9. Configure MySQL
#复制mysql服务启动配置文件, add the MySQL startup service to the system service and view
Cd/home/formal/mysql
CP support-files/my-medium.cnf./my.cnf
14 is shown below:

Note: When starting the MySQL service, will be in a certain order to search my.cnf, first in the/etc directory, find will search "$basedir/my.cnf", in this case is/home/formal/mysql/ MY.CNF, this is the default location for the new MySQL configuration file!
#配置my. CNF added below Mysqld
VI my.cnf
Basedir =/home/formal/mysql/
DataDir =/home/formal/mysql/data
15 is shown below:

#在log-bin=mysql-bin below to prevent unlimited disk usage
max_binlog_size=100m
Expire_logs_days=7
16 is shown below:

#创建系统数据库的表--Specifies the profile and user
scripts/mysql_install_db--defaults-file=./my.cnf--user=formal
17 is shown below:

View Execute "Create a System database table-Specifies the configuration file and the user" "The success of the previous step to perform a task" succeeds, 0 indicates success, and the other identity fails.
18 is shown below:

10. Set up MySQL
#启动mysql
Cd/home/formal/mysql/bin
./mysqld_safe &
19 is shown below:


Login Database
#进入mysql命令行模式 Modify the root user password for MySQL and open the remote connection
./mysql-u root–p//No password, enter directly
20 is shown below:


#为root添加远程连接的能力.
#修改密码
#让设置生效
Use MySQL;
Grant all privileges on * * to [email protected] '% ' identified by ' root ';
Update user Set Password = Password (' xushouweidb ') where user= ' root ';
Flush privileges;
Exit
21 is shown below:

11. Set up MySQL service following system auto-start
Mode one: Using the Configuration service
Cp/home/formal/mysql/support-files/mysql.server/etc/init.d/mysqld
chmod +x/etc/init.d/mysqld
Chkconfig--add mysqld
Chkconfig mysqld on
Mode two: How to execute a script using a timed task
Here I mainly introduce the timing task execution script mode. Mode one may wish to refer to network resources or execute the above command code form, here I do not say more!
Go to the/home/formal/directory and create a task directory under that directory
cd/home/formal/
mkdir Task
ll
22 is shown below:

Go to the Task directory, create mysql_auto_restart.sh and Mysql_auto_restart.log files, and view.
CD task/
Touch mysql_auto_restart.sh Mysql_auto_restart.log
ll
23 is shown below:

//Edit mysql_auto_restart.sh, add the following script code, Shell script programming, please refer to network resources, I do not introduce you here.
Vi/vim mysql_auto_restart.sh
Add script code:
#!/bin/bash
#/usr/bin/nmap localhost | grep 3306
#lsof-i:3306
myport=6603
mysqlport= ' Netstat-na|grep "LISTEN" |grep $MYPORT |awk-f[: ""]+ ' nr==1 {print $4} '
mysql=/home/ Formal/mysql/bin/mysql
Myuser=root
mypass=xushouweidb
Function Checkmysqlstatus () {
$MYSQL-u$myuser- P$mypass--connect_timeout=5-e "show databases;" &>/dev/null 2>&1
If [$?-ne 0]
then
Restartm Ysqlservice
If ["$MYSQLPORT" = = $MYPORT];then
Echo ' date ': $MYSQL restart successful ... "
Else
Echo ' Date ': $MYSQL restart failure ... "
Echo ' date ': $MYSQL is down, please try the restart MYSQL by M anual! ">/var/log/mysqlerr
echo" e-mail here: "
Fi
Else
Echo ' Date ': $MYSQL is running ..."
Fi
}

function Restartmysqlservice () {
echo ' Date ': Try to restart the MySQL service ... "
/home/formal/mysql/bin/mysqld_safe
Mysqlport= ' Netstat-na|grep "LISTEN" |grep $MYPORT |awk-f[: "]+ ' nr==1 {print $} '
}

If ["$MYSQLPORT" = = = $MYPORT]
Then
Checkmysqlstatus
Else
Restartmysqlservice
Fi

After inserting the above code, press ESC->:WQ save to exit!
24 is shown below:

Add executable permissions for mysql_auto_restart.sh execution script file
chmod +x./mysql_auto_restart.sh
ll
25 is shown below:

View and add timed execution tasks
You may be prompted when you execute the statement: no crontab for formal
Crontab-l
Crontab-e
Add a timed task code
* * * * * */home/formal/task/mysql_auto_restart.sh >>/home/formal/task/mysql_auto_restart.log
26 is shown below:


Execute the mysql_auto_restart.sh script (you can also do this here, since the scheduled execution time has been set)
./mysql_auto_restart.sh
If the MySQL service has been started, the following information will be reported, prompting you to start the MySQL service
27 is shown below:

Use the root user to restart the CentOS server, log in to the server, and switch to formal user and log in to MySQL. Check to see if the MySQL service follows the machine boot.
Reboot
Su-formal
Cd/home/formal/mysql/bin
./mysql-uroot-pxushouweidb
28 is shown below:

At this point, centos6.7 use a non-root user to install MySQL and use a timed task to execute a script randomly start the MySQL service, the process has gone, we are opposite typos or other problems have problems, please contact me, I immediately correct, No.: Jasxu360, thank you!

CentOS6.7 using a non-root user (normal user) compile and install the MySQL database and implement the MySQL database service random auto-start using the Shell Script timed task mode

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.