linux安装mysql(shell一键安装)
1. 相关文件(install_mysql.sh、my.cnf、mysqld相关内容在文中最后面)
2. 将上面的文件上传到linux服务器某一目录下
3.给install_mysql.sh赋执行权限
# chmod +x instll_mysql.sj
4. 执行install_mysql.sh
# ./install_mysql.sh
5. 验证
6. install_mysql.sh内容
#!/bin/sh
#获取当前路径
mypath=$(cd $(dirname $0)/; pwd)
#安装目标路径
dirpath=/usr/local/src/mysql
mkdir ${dirpath}
#相关软件安装
cd /
yum -y install gcc
yum -y intall gcc-c++
yum -y install ncurses-devel
#安装cnake
cd ${dirpath}
wget --no-check-certificate http://www.cmake.org/files/v2.8/cmake-2.8.8.tar.gz
tar zxvf cmake-2.8.8.tar.gz
cd ${dirpath}/cmake-2.8.8
./configure
make
make install
#添加mysql用户组
groupadd mysql
useradd -g mysql mysql -s /bin/false
#mysql数据存储目录
mkdir -p /data/mysql
chown -R mysql:mysql /data/mysql
#mysql安装目录
mkdir -p /usr/local/mysql
#安装mysql
tar zxvf ${mypath}/mysql-5.5.59.tar.gz -C ${dirpath}
cd ${dirpath}/mysql-5.5.59
cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/data/mysql -DSYSCONFDIR=/etc
make
make install
#配置my.cnf(我这里是用本地搞好的my.cnf直接替换)
cp /etc/my.cnf /etc/my.cnf_bak_`date +%Y%m%d`
/bin/cp -rf ${mypath}/my.cnf /etc/my.cnf
#生产mysql的系统数据库
cd /usr/local/mysql
./scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql
#配置mysqld(我这里是用本地搞好的mysqld直接复制)
/bin/cp -rf ${mypath}/mysqld /etc/rc.d/init.d/mysqld
chmod 755 /etc/init.d/mysqld
#开机启动mysql(可选)
chkconfig mysqld on
#启动mysql
service mysqld start
#配置环境变量
profile=/etc/profile
path="export PATH=$PATH:/usr/local/mysql/bin"
echo $path >> $profile
source /etc/profile
. /etc/profile
#建立相关软连接
ln -s /usr/local/mysql/lib/mysql /usr/lib/mysql
ln -s /usr/local/mysql/include/mysql /usr/include/mysql
ln -s /usr/local/mysql/bin/mysql /usr/bin
#创建mysql root用户密码(只有在第一次安装的时候才有用)
/usr/local/mysql/bin/mysqladmin -u root password "sa"
#重启mysql
service mysqld restart
7. my.cnf内容(最下面增加一行)
datadir = /data/mysql
8. mysqld内容(修改2行)
basedir=/usr/local/mysql
datadir=/data/mysql