1.创建存放mysql软件包的目录
mkdir -p /home/coco/tools
cd /home/coco/tools
rz -y #上传cmake软件及mysql数据库软件,虚拟机可以直接通过拖拽实现
2.安装cmake
tar xf cmake-2.8.8.tar.gz
cd cmake-2.8.8
./configure
gmake
gmake install
cd ..
3.依赖包安装
yum install ncurses-devel -y #若yum失败,可以先执行yum clean all,再yum makecache
4.安装及部署mysql
4.1)创建用户和组
groupadd mysql
useradd mysql -s /sbin/nologin -M -g mysql
4.2)解压编译mysql
tar xf mysql-5.5.32.tar.gz
cd mysql-5.5.32
#通过cmake编译安装mysql
cmake . -DCMAKE_INSTALL_PREFIX=/application/mysql-5.5.32 \
-DMYSQL_DATADIR=/application/mysql-5.5.32/data \
-DMYSQL_UNIX_ADDR=/application/mysql-5.5.32/tmp/mysql.sock \
-DDEFAULT_CHARSET=utf8 \ %不写即选默认的字符集
-DDEFAULT_CHARSET=utf8_general_ci \ %不写即选默认的字符集
-DEXTRA_CHARSETS=gbk,gb2312,utf8,ascii \
-DENABLED_LOCAL_INFILE=ON \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_FEDERATED_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 \
-DWITHOUT_PARTITION_STORAGE_ENGINE=1 \
-DWITH_FAST_MUTEXES=1 \
-DWITH_ZLIB=bundled \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_READLINE=1 \
-DWITH_EMBEDDED_SERVER=1 \
-DWITH_DEBUG=0
#build files 在/home/coco/tools/mysql-5.5.32下有模板供修改使用
make
make install
ln -s /application/mysql-5.5.32/ /application/mysql #做一个link
cd ..
cp mysql-5.5.32/support-files/my-small.cnf /etc/my.cnf #my-small.cnf为mysql配置文件供修改使用
4.3)配置环境变量
echo 'export PATH=/application/mysql/bin:$PATH' >>/etc/profile
tail -l /etc/profile
source /etc/profile
echo $PATH
4.4)初始化数据文件
mkdir -p /application/mysql/data/
ll /application/mysql/data/
chown -R mysql.mysql /application/mysql/data/
chmod -R 1777 /tmp/
cd /application/mysql/scripts/
./mysql_install_db --basedir=/application/mysql/ --datadir=/application/mysql/data/ --user=mysql #初始化
4.5)配置开机自启动脚本
cd /home/coco/tools/mysql-5.5.32
/bin/cp support-files/mysql.server /etc/init.d/mysqld #mysql.server为启动脚本供修改使用
chmod +x /etc/init.d/mysqld
/etc/init.d/mysqld start #显示SUCCESS即启动成功
netstat -lntup|grep 3306 #通过网络端口确保mysql启动成功
mysql #登录数据库,根据前面的环境变量配置可执行
#设置终端模式开机启动
chkconfig mysqld on
chkconfig --list mysqld
4.6)数据库环境整理
select user.host from mysql.user;
#删除没有用的用户表
delete from mysql.user where user=' ';
delete from mysql.user where host='www';
delete from mysql.user where host='::1';
#删除没有用的database
drop database test;
show databases;
#添加额外的数据库管理员system
grant all privileges on *.* to system@' localhost' identified by 'oldboy123' with grant option; (with grant option赋予system用户添加其他用户的权限)
2018年10月27日
祝好!