下载安装包:mysql-5.5.30.tar.gz
1.首先需要创建mysql用户
1shell>groupadd mysql2shell>useradd -s /sbin/nologin -g mysql mysql #设置mysql默认bash为nologin,不允许登录系统
2.依赖关系
shell>yum install ncurses2shell>yum install ncurses-devel3shell>yum install gcc libgcc gcc-c++ compat-gcc4 shell>yum install libtool libtool-ltdl-develbisoncmake.x86_64 libtool-ltdl-devel.x86_64 libtool.x86_64
3.解压源码包
shell>tar -zxvf mysql-5.5-tar.bzshell>cd mysql-5.5
4.编译安装三部曲
#####编译
shell>cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/data/dbdata -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DWITH_PERFSCHEMA_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_MYISAM_STORAGE_ENGINE=1 -DMYSQL_TCP_PORT=3306 -DENABLED_LOCAL_INFILE=1 -DWITH_EXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_SSL=yes
编译参数解释:
#一般选项:-DCMAKE_INSTALL_PREFIX=/usr/local/mysql #指定基本安装目录,这个参数可以在服务启动时候用--basedir参数指定 -DMYSQL_DATADIR=/data/dbdata #指定mysql data文件存放目录#存储引擎:-DWITH_INNOBASE_STORAGE_ENGINE=1-DWITH_BLACKHOLE_STORAGE_ENGINE=1-DWITH_ARCHIVE_STORAGE_ENGINE=1-DWITH_PARTITION_STORAGE_ENGINE=1-DWITH_PERFSCHEMA_STORAGE_ENGINE=1-DWITH_MYISAM_STORAGE_ENGINE=1#功能选项:-DMYSQL_UNIX_ADDR=/usr/local/mysql/tmp/mysql.sock #指定sock文件存放位置,默认位置是/tmp/mysql.sock-DMYSQL_TCP_PORT=3306 #监听端口-DENABLED_LOCAL_INFILE=1 #Whether to enable LOCAL capability in the client library fo r LOAD DATA INFILE.-DWITH_EXTRA_CHARSETS=all-DDEFAULT_CHARSET=utf8-DDEFAULT_COLLATION=utf8_general_ci-DWITH_SSL=yes #ssl支持
shell>make && make install #如果这两步骤中出错,请检查是否缺少依赖包,文章开头已经列出所有需要安装的依赖包
5.初始化数据库及配置
##权限
shell>cd /usr/local/mysqlshell>chown mysql:mysql -R .shell>mkdir -p /data/dbdatashell>chown mysql:mysql /data/dbdata
#复制配置文件
shell>cp /root/mysql-5.5.30/support-files/my-large.cnf /etc/my.cnfshell>cp /root/mysql-5.5.30/support-files/mysql.server /etc/init.d/mysqldshell>chmod 755 /etc/init.d/mysqld
#初始化数据库
shell>/usr/local/mysql/scripts/mysql_install_db --user=mysql
mysql 添加环境变量
#1.查看当前变量
shell>echo $PATH
/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
#2.修改默认PATH变量,添加/usr/local/mysql/bin路径
shell>vim /etc/profile.d/myfile.sh #手动创建export PATH=${PATH}:/usr/local/mysql/binshell>source /etc/profile.d/myfile.sh