mysql安装及允许远程访问
use mysql;
delete from user where user='';
grant all privileges on *.* to 'root'@'%' identified by '123456' with grant option;
flush privileges;
service mysql restart
===================安装脚本==============================
#!/bin/bash #----------install packages---------- yum -y install perl perl-Module-Install.noarch #----------setting mysql install directory---------- function install_dir(){ echo 'Please input mysql isntall dir[/usr/local]:' read dir1 if [ -z $dir1 ] then dir1='/usr/local' fi echo 'Install dir is 【'$dir1'】' } install_dir #----------setting mysql data directory---------- function mysql_data(){ echo 'Please input mysql_data dir[/usr/local/mysql/data]:' read dir2 if [ -z $dir2 ] then dir2='/usr/local/mysql/data' fi echo 'mysql_data dir is 【'$dir2'】' } mysql_data #----------setting mysql port ---------- function mysql_port(){ echo 'Please input mysql_port[3306]:' read port1 if [ -z $port1 ] then port1='3306' fi echo 'mysql_port is 【'$port1'】' } mysql_port #----------add mysql user and group---------- mkdir -p $dir1/mysql mkdir -p $dir2 groupadd mysql useradd -g mysql -d $dir1/mysql mysql #log echo 'mysql install dir:'$dir1'/mysql'>>./install.log echo 'mysql data dir:'$dir2>>./install.log echo 'mysql port:'$port1>>./install.log function setting2(){ rm -rf /etc/my.cnf rm -rf /etc/init.d/mysql cp $dir1/mysql/support-files/my-default.cnf /etc/my.cnf cp $dir1/mysql/support-files/mysql.server /etc/init.d/mysql dir11='basedir='$dir1'/mysql' dir12='datadir='$dir2 port11='port ='$port1 sed -i '46d' /etc/init.d/mysql sed -i '46d' /etc/init.d/mysql sed -i "46a\\$dir11" /etc/init.d/mysql sed -i "47a\\$dir12" /etc/init.d/mysql sed -i "23a\\$port11" /etc/my.cnf sed -i '/MYSQL_HOME/d' /etc/profile echo 'export MYSQL_HOME='$dir1'/mysql'>>/etc/profile echo 'export PATH=$PATH:$MYSQL_HOME/bin'>>/etc/profile source /etc/profile echo 'Mysql Install Successfull' } function setting1(){ rm -rf $dir1/mysql/* cp -R mysql-5.6.36-linux-glibc2.5-x86_64/* $dir1/mysql/ echo 'start install database......' $dir1/mysql/scripts/mysql_install_db --user=mysql --basedir=$dir1/mysql --datadir=$dir2 declare -i p1 sum=0 while(($sum<=10)) do sleep 1 if [ $sum -gt 3 ] then p1=`ps -ef|grep mysql_install_db |grep -v "grep" |awk '{print $2}'` if [ $p1 -eq 0 ] then sleep 5 setting2 break fi sum=1 fi let "sum++" done } #----------install database start---------- src_path='mysql-5.6.36-linux-glibc2.5-x86_64' if [ ! -d $src_path ] then tar -xvf mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz declare -i p2 sum=0 while(($sum<=10)) do sleep 1 if [ $sum -gt 3 ] then p2=`ps -ef|grep mysql-5.6.36 |grep -v "grep"|awk '{print $2}'` if [ $p2 -eq 0 ] then sleep 10 setting1 break fi sum=1 fi let "sum++" done else setting1 fi