环境要求:
主机名 | IP地址 | 需要软件及版本 | 系统版本 |
---|---|---|---|
mysql.mfyxw.com | 192.168.80.135 | Mysql5.5.33 | 5.5.33 |
1.设定主机名
hostnamectl set-hostname mysql.mfyxw.com
2.关闭Selinux及防火墙(实际生产环境不建议关闭防火墙)
~]#setenforce 0 && sed -i s/^SELINUX=.*/SELINUX=disabled/g /etc/sysconfig/selinux
~]#systemctl stop firewalld && systemctl disable firewalld
3.从MySQL官网下载源码包
MySQL 5.5.33源码包地址:https://downloads.mysql.com/archives/get/p/23/file/mysql-5.5.33.tar.gz
把下载好的MySQL5.5.33上传到服务器
4.安装编译环境
~]#yum -y install cmake gcc gcc-c++
5.源码编译安装bison-2.5.1**
#查看是否有bison,如有,请先删除原来的,再编译安装。如果版本太高,make会出现问题
~]#rpm -qa bison
~]#yum erase bison
#解压bison并编译安装
~]#tar xf bison-2.5.1.tar.gz
~]#cd bison-2.5.1
~]#./configure && make && make install
6.创建mysql用户及组,数据存放目录及授权
#创建mysql系统组
~]#groupadd -r mysql
#创建mysql系统用户
~]#useradd -g mysql -r -d /mydata/data mysql
#创建存放数据目录并授权给mysql组
~]#mkdir -p /mydata/data
~]#chown -R .mysql /mydata
7.解决编译安装mysql依赖包
yum -y install ncurses-devel
8.源码编译安装MySQL 5.5.33
#解压mysql5.5.33
~]#tar xf mysql-5.5.33.tar.gz
~]#cd mysql-5.5.33
#编译安装mysql-5.5.33
~]#cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/mydata/data -DSYSCONFDIR=/etc -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DWITH_SSL=bundled -DWITH_ZLIB=system -DWITH_LIBWRAP=0 -DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci
~]#make && make install
9.为编译指定安装mysql的目录/usr/local/mysql授权
~]#chown -R .mysql /usr/local/mysql
10.为mysql提供环境变量
cat > /etc/profile.d/mysql.sh << EOF
export PATH=/usr/local/mysql/bin:$PATH
EOF
#重启文件
~]#source /etc/profile.d/mysql.sh
11.初始化mysql数据库
~]#cd /usr/local/mysql
~]#scripts/mysql_install_db --user=mysql --datadir=/mydata/data
12.把编译安装生成的样本配置文件复制到/etc目录**
~]#cd /usr/local/mysql/support-files
~]#cp my-large.cnf /etc/my.cnf
#在mysql配置文件my.cnf中的[mysqld]段添加如下一行
datadir = /mydata/data
13.添加mysql服务脚本
~]#/cd /usr/local/mysql/support-files
~]#cp mysql.server /etc/rc.d/init.d/mysqld
~]#chmod a+x /etc/rc.d/init.d/mysqld
#添加开机自启
~]#chkconfig --add mysqld
~]#chkconfig --list mysqld
#启动mysql服务
~]#service mysqld start
14.查看mysql默认开放的端口
~]#ss -tanl
15.删除匿名用户
#登录mysql
~]#mysql
~]#mysql>USE mysql
~]#mysql>SELECT host,user,password FROM user;
~]#mysql>DROP USER ''@localhost;
~]#mysql>DROP USER ''@mysql.mfyxw.com;
~]#mysql>DROP USER root@'::1'
~]#mysql>SELECT host,user,password FROM user;
16.为mysql的root用户设置密码(此处设置为同一个)
~]#mysql>UPDATE user SET password=PASSWORD('mypass') WHERE user='root';
~]#mysql>SELECT host,user,password FROM user;