后面要简单写一个MySQL自动部署脚本,今天再次梳理下安装流程。同时也给刚入门的同学一个参考,写的比较详细,图文并茂。希望能一举两得。
安装环境:
CentOS 6.2,最小化安装确保后期做脚本时有较好的兼容性
MySQL 5.5源码包(/usr/toolkits/mysql_install_tools/mysql-5.5.54.tar.gz)
一、规划安装目录、用户、组
安装路径:/usr/local/mysql
数据目录:/usr/local/mysql/data
日志目录:/usr/local/mysql/log
参数文件:/usr/local/mysql/my.cnf
sock、pid文件:/usr/local/mysql/run/mysql.sock | mysqld.pid
添加用户、组
groupadd mysql
useradd -s /sbin/nologin -M -g mysql mysql
授权:
chmod +x /usr/local/mysql
chown -R mysql:mysql /usr/local/mysql
二、配置环境变量、安装编译工具
gcc、gcc-c++、bison、ncurses-devel、zlib、openssl、cmake
1、gcc
2、gcc-c++
3、bison
4、ncurses-devel
5、zlib
6、openssl
7、openssl-devel
8、cmake
三、编译安装MySQL
# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DSYSCONFDIR=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/data -DMYSQL_UNIX_ADDR=/usr/localmysql/run/mysqld.sock -DMYSQL_TCP_PORT=3306 -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSETS=all -DWITH_SSL=system -DWITH_ZLIB=system -DENABLED_LOCAL_INFILE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_FEDERATED_STORAGE_ENGINE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DWITH_READLINE=1
四、MySQL参数配置
cp support-files/my-medium.cnf /usr/local/mysql/my.cnf
按需配置my.cnf
五、设置开机自启
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
chmod +x /etc/init.d/mysql
chkconfig --add mysql
chkconfig --level 345 mysql on
六、初始化MySQL
/usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data/ --user=mysql
七、启动、登录MySQL