51工具盒子

依楼听风雨
笑看云卷云舒,淡观潮起潮落

Centos7.5编译安装mysql5.5

当然环境Centos7.5,mysql版本5.5.59,同样也适用于Centos6.9系统

1、安装依赖
yum install gcc-c++ ncurses-devel

|---|-----------------------------------| | 1 | yum install gcc-c++ ncurses-devel |

2、为mysql创建用户
useradd -s /bin/false -M mysql

|---|--------------------------------| | 1 | useradd -s /bin/false -M mysql |

3、下载mysql5.5源码包
cd /usr/local/src/ wget https://cdn.mysql.com//Downloads/MySQL-5.5/mysql-5.5.59.tar.gz tar zxf mysql-5.5.59.tar.gz cd mysql-5.5.59

|---------|------------------------------------------------------------------------------------------------------------------------------------| | 1 2 3 4 | cd /usr/local/src/ wget https://cdn.mysql.com//Downloads/MySQL-5.5/mysql-5.5.59.tar.gz tar zxf mysql-5.5.59.tar.gz cd mysql-5.5.59 |

4、安装cmake

mysql从5.5版本开始,不再使用./configure编译,而是使用cmake编译器,具体的cmake编译参数可以参考mysql官网文档

http://dev.mysql.com/doc/refman/5.5/en/source-configuration-options.html
yum install cmake

|---|-------------------| | 1 | yum install cmake |

5、编译安装
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DSYSCONFDIR=/etc -DMYSQL_TCP_PORT=3306 -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DWITH_FEDERATED_STORAGE_ENGINE=1 -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8mb4 -DDEFAULT_COLLATION=utf8mb4_general_ci -DWITH_READLINE=1 -DWITH_EMBEDDED_SERVER=1 -DENABLED_LOCAL_INFILE=1 make make install

|-------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | 1 2 3 | cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DSYSCONFDIR=/etc -DMYSQL_TCP_PORT=3306 -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DWITH_FEDERATED_STORAGE_ENGINE=1 -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8mb4 -DDEFAULT_COLLATION=utf8mb4_general_ci -DWITH_READLINE=1 -DWITH_EMBEDDED_SERVER=1 -DENABLED_LOCAL_INFILE=1 make make install |

参数解释:

-DCMAKE_INSTALL_PREFIX=/usr/local/mysql 设置mysql安装目录
-DSYSCONFDIR=/etc 指定配置文件目录
-DMYSQL_TCP_PORT=3306 指定端口3306,默认就是3306
-DWITH_MYISAM_STORAGE_ENGINE=1 安装myisam存储引擎
-DWITH_INNOBASE_STORAGE_ENGINE=1 安装innodb存储引擎
-DWITH_PARTITION_STORAGE_ENGINE=1 安装数据库分区
-DWITH_FEDERATED_STORAGE_ENGINE=1 安装federated存储引擎
-DEXTRA_CHARSETS=all 安装所有扩展字符集
-DDEFAULT_CHARSET=utf8mb4 使用utf8mb4字符集
-DDEFAULT_COLLATION=utf8mb4_general_ci 校验字符集
-DWITH_READLINE=1 启用readline库支持
-DWITH_EMBEDDED_SERVER=1 编译嵌入式服务器支持
-DENABLED_LOCAL_INFILE=1 允许从本地导入数据

6、修改mysql安装目录属主属组
chown -R mysql:mysql /usr/local/mysql/

|---|----------------------------------------| | 1 | chown -R mysql:mysql /usr/local/mysql/ |

7、初始化数据库
/usr/local/mysql/scripts/mysql_install_db --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql --datadir=/usr/local/mysql/var --user=mysql

|---|----------------------------------------------------------------------------------------------------------------------------------------------| | 1 | /usr/local/mysql/scripts/mysql_install_db --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql --datadir=/usr/local/mysql/var --user=mysql |

8、配置my.cnf
mv /etc/my.cnf /etc/my.cnf.bak && wget -O /etc/my.cnf https://down.whsir.com/downloads/my5.5.cnf mkdir /var/lib/mysql chown -R mysql.mysql /var/lib/mysql

|-------|-------------------------------------------------------------------------------------------------------------------------------------------------------------| | 1 2 3 | mv /etc/my.cnf /etc/my.cnf.bak && wget -O /etc/my.cnf https://down.whsir.com/downloads/my5.5.cnf mkdir /var/lib/mysql chown -R mysql.mysql /var/lib/mysql |

9、复制mysql服务启动配置文件
cp support-files/mysql.server /etc/init.d/mysql chmod +x /etc/init.d/mysql

|-----|----------------------------------------------------------------------------| | 1 2 | cp support-files/mysql.server /etc/init.d/mysql chmod +x /etc/init.d/mysql |

10、设置软连接或自行添加环境变量
ln -sv /usr/local/mysql/bin/mysql /usr/local/sbin/mysql

|---|---------------------------------------------------------| | 1 | ln -sv /usr/local/mysql/bin/mysql /usr/local/sbin/mysql |

11、启动mysql服务
/etc/init.d/mysql start

|---|-------------------------| | 1 | /etc/init.d/mysql start |

默认密码为空

12、修改密码

进入mysql
mysql -uroot -p mysql> set password = password('whsir');

|-----|-----------------------------------------------------------| | 1 2 | mysql -uroot -p mysql> set password = password('whsir'); |

至此mysql5.5编译安装完成,相关配置参数请自行根据使用情况进行调整

附:设置环境变量方法
vi /etc/profile
export PATH=$PATH:/usr/local/mysql/bin/
source /etc/profile

赞(0)
未经允许不得转载:工具盒子 » Centos7.5编译安装mysql5.5