mysql database installation script and process

Things to note when running this script:
*Firewall and selinux are turned off.

1. The yum source is correctly configured and running

2. The source code packages cmake-2.8.6.tar.gz and mysql-5.6.36.tar.gz have been uploaded to the root home directory.

  1. Solve the problem that the -f option of the cp command still prompts for forced copying.
    This is caused by the alias of the cp command being 'cp -i'.

[root@localhost ~]# unalias cp

**mysql deployment takes about 30 minutes


[root@localhost ~]# vim mysql_install.sh

#!/bin/bash

yum -y install ncurses-devel

#Extract cmake and install the basic environment
tar xf /root/cmake-2.8.6.tar.gz -C /usr/src/

cd /usr/src/cmake-2.8.6

#Configure, compile and install cmake

./configure && gmake && gmake install

#Unzip mysql

cd

tar zxvf /root/mysql-5.6.36.tar.gz -C /usr/src/

cd /usr/src/mysql-5.6.36/

#cmake configure mysql

cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS=all -DSYSCONFDIR=/etc/

make &&make install

#1.Copy configuration file

cp -f /usr/src/mysql-5.6.36/support-files/my-default.cnf /etc/my.cnf

#2. Add system service
cp -f /usr/src/mysql-5.6.36/support-files/mysql.server /etc/rc.d/init.d/mysqld

chmod +x /etc/rc.d/init.d/mysqld

chkconfig --add mysqld

chkconfig mysqld on

#3. Optimize the PATH path, which is convenient when executing commands. Both single and double quotes will work.

echo “export PATH=$PATH:/usr/local/mysql/bin” >>/etc/profile

#4. Initialize mysql, create users, and empower

useradd -M -s /sbin/nologin mysql

chown -R mysql:mysql /usr/local/mysql

/usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql

/etc/rc.d/init.d/mysqld start

chkconfig mysqld on

netstat -anput |grep 3306

/usr/local/mysql/bin/mysqladmin -u root password 123


[root@localhost ~]# chmod +x mysql_install.sh

[root@localhost ~]# ./mysql_install.sh

The source command is executed in the script and can only take effect in the subshell of the script. Therefore, run this command after the script is executed.

source /etc/profile

Guess you like

Origin blog.csdn.net/m0_57207884/article/details/119669752