MySQL5.5.52编译安装
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了MySQL5.5.52编译安装相关的知识,希望对你有一定的参考价值。
一、mysql介绍
MySQL是一个关系型数据库管理系统,由瑞典MySQL AB 公司开发,目前属于 Oracle 旗下公司。MySQL 最流行的关系型数据库管理系统,在 WEB 应用方面MySQL是最好的 RDBMS (Relational Database Management System,关系数据库管理系统) 应用软件之一。
MySQL是一种关联数据库管理系统,关联数据库将数据保存在不同的表中,而不是将所有数据放在一个大仓库内,这样就增加了速度并提高了灵活性。
MySQL所使用的 SQL 语言是用于访问数据库的最常用标准化语言。MySQL 软件采用了双授权政策,它分为社区版和商业版,由于其体积小、速度快、总体拥有成本低,尤其是开放源码这一特点,一般中小型网站的开发都选择 MySQL 作为网站数据库。
二、MySQL的版本选择
技巧1.选择版本GA版本,Development版本、Alpha版本和Beta版本一般不用在项目中。因为它们肯定存在重大的问题或某些功能未完全实现。
技巧2.选择GA版本,不要选择最新,一般选择前3-4个版本或10个月前的版本。
技巧3.查看官方说明,没有重大bug更新的版本
三、安装介绍
MySQL从5.3开始使用cmake的安装方式。
本次版本选择用户量最多的MySQL5.5系列,分别给出本次需要的5.5.52和最新版的下载地址
MySQL5.5系下载地址
http://dev.mysql.com/downloads/mysql/5.5.html#downloads
四、安装前准备
当前系统
[[email protected] ~]# cat /etc/redhat-release CentOS release 6.8 (Final) [[email protected] ~]# uname -r 2.6.32-642.el6.x86_64 [[email protected] ~]# uname -m x86_64 [[email protected] ~]# uname -n db01
1、上传所需要的MySQL编译安装包
可以使用rz,ftp等工具上传至指定目录;
演示: 我的存放目录用户的家目录下
[[email protected] ~]# mkdir -p /server/tools [[email protected] ~]# cd /server/tools [[email protected] tools]# rz rz waiting to receive. Starting zmodem transfer. Press Ctrl+C to cancel. Transferring mysql-5.5.52.tar.gz... 100% 20539 KB 20539 KB/sec 00:00:01 0 Errors [[email protected] tools]# [[email protected] tools]# ll 总用量 20540 -rw-r--r-- 1 root root 21032776 8月 26 17:32 mysql-5.5.52.tar.gz
2、安装cmake工具
MySQL从5.3开始使用cmake工具安装
cmake工具地址https://cmake.org/files/v3.5/cmake-3.5.2.tar.gz
演示:
1)下载工具
[[email protected] tools]# pwd /server/tools [[email protected] tools]# wget https://cmake.org/files/v3.5/cmake-3.5.2.tar.gz [[email protected] tools]# ls -l cmake-3.5.2.tar.gz -rw-r--r-- 1 root root 6863498 4月 16 01:40 cmake-3.5.2.tar.gz
2)解压cmake3.5.2
[[email protected] tools]# tar xf cmake-3.5.2.tar.gz [[email protected] tools]# ls -ld cmake-3.5.2 drwxr-xr-x 11 root root 4096 4月 27 09:45 cmake-3.5.2
3)安装cmake3.5.2
[[email protected] tools]# cd cmake-3.5.2 [[email protected] cmake-3.5.2]# ./configure [[email protected] cmake-3.5.2]# gmake [[email protected] cmake-3.5.2]# gmake install [[email protected] cmake-3.5.2]# cd ../
PS:如果嫌弃麻烦那么 yum安装也可以(yum install -y cmake)
[[email protected] tools]# yum install -y cmake
3、安装ncurses-devel依赖
ncurses,计算机语言,指的是提供字符终端处理库。
[[email protected] tools]# yum install -y ncurses-devel
4、安装MySQL
1)创建用户和组
[[email protected] tools]# useradd -Ms /sbin/nologin mysql [[email protected] tools]# id mysql uid=501(mysql) gid=501(mysql) 组=501(mysql)
2)解压编译安装
[[email protected] tools]# tar xf mysql-5.5.52.tar.gz [[email protected] tools]# cd mysql-5.5.52 [[email protected] mysql-5.5.52]# cmake . -DCMAKE_INSTALL_PREFIX=/application/mysql-5.5.52 -DMYSQL_DATADIR=/application/mysql-5.5.52/data -DMYSQL_UNIX_ADDR=/application/mysql-5.5.52/tmp/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=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 ………………………省略…………………………… oaded-virtual -Wno-unused-parameter -- CMAKE_C_FLAGS_RELWITHDEBINFO: -O2 -g -DNDEBUG -DDBUG_OFF -DMY_PTHREAD_FASTMUTEX=1 -- CMAKE_CXX_FLAGS_RELWITHDEBINFO: -O2 -g -DNDEBUG -DDBUG_OFF -DMY_PTHREAD_FASTMUTEX=1 -- Configuring done -- Generating done -- Build files have been written to: /server/tools/mysql-5.5.52 [[email protected] mysql-5.5.52]# echo $? 0
<==显示如上结果配置成功
参数解释解释:
cmake . -DCMAKE_INSTALL_PREFIX=/application/mysql-5.5.52 \ #指定安装目录 -DMYSQL_DATADIR=/application/mysql-5.5.52/data \ #指定数据存放目录(重要) -DMYSQL_UNIX_ADDR=/application/mysql-5.5.52/tmp/mysql.sock \ #指定sock的路径 -DDEFAULT_CHARSET=utf8 \ #指定默认字符集 -DDEFAULT_COLLATION=utf8_general_ci \ #指定校准字符集编码 -DEXTRA_CHARSETS=gbk,gb2312,utf8,ascii \ #安装所需字符集 -DENABLED_LOCAL_INFILE=ON \ #启用加载本地数据 -DWITH_INNOBASE_STORAGE_ENGINE=1 \ #支持innode储存引擎 -DWITH_FEDERATED_STORAGE_ENGINE=1 \ #支持federated引擎 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \ #支持黑洞储存引擎 -DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 -DWITHOUT_PARTITION_STORAGE_ENGINE=1 \ #安装支持数据库分区 -DWITH_FAST_MUTEXES=1 -DWITH_ZLIB=bundled \ #zlib压缩模式 -DENABLED_LOCAL_INFILE=1 -DWITH_READLINE=1 -DWITH_EMBEDDED_SERVER=1 -DWITH_DEBUG=0 #禁用debug,开启影响性能
提示,编译时可配置的选项很多,具体可参考结尾官方文档
3)编译安装
[[email protected] mysql-5.5.52]# make ………………………省略…………………………… [100%] Built target my_safe_process [[email protected] mysql-5.5.52]# echo $? 0 <==编译成功 [[email protected] mysql-5.5.52]# make install ………………………省略…………………………… -- Installing: /application/mysql-5.5.52/man/man1/mysqlslap.1 -- Installing: /application/mysql-5.5.52/man/man8/mysqld.8 [[email protected] mysql-5.5.52]# echo $? 0 <==安装成功
如果上述操作未出现错误,则MySQL5.5.52软件cmake方式的安装就算成功了
4)创建软连接,去除版本号
[[email protected] mysql-5.5.52]# ln -s /application/mysql-5.5.52/ /application/mysql
5、复制MySQL配置文件到/etc目录下
[[email protected] mysql-5.5.52]# \cp /application/mysql/support-files/my-small.cnf /etc/my.cnf
6、配置环境变量
[[email protected] mysql-5.5.52]# echo ‘export PATH=/application/mysql/bin:$PATH‘ >>/etc/profile [[email protected] mysql-5.5.52]# tail -1 /etc/profile export PATH=/application/mysql/bin:$PATH [[email protected] mysql-5.5.52]# source /etc/profile [[email protected] mysql-5.5.52]# echo $PATH /application/mysql/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
7、赋予目录用户组
[[email protected] mysql-5.5.52]# chown -R mysql.mysql /application/mysql/
8、执行数据库初始化脚本
[[email protected] mysql-5.5.52]# cd /application/mysql/scripts/ [[email protected] scripts]# ./mysql_install_db > --basedir=/application/mysql-5.5.52 > --datadir=/application/mysql-5.5.52/data > --user=mysql Installing MySQL system tables... 161210 15:00:47 [Note] /application/mysql-5.5.52/bin/mysqld (mysqld 5.5.52) starting as process 21047 ... OK Filling help tables... 161210 15:00:48 [Note] /application/mysql-5.5.52/bin/mysqld (mysqld 5.5.52) starting as process 21054 ... OK To start mysqld at boot time you have to copy support-files/mysql.server to the right place for your system PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER ! To do so, start the server, then issue the following commands: /application/mysql-5.5.52/bin/mysqladmin -u root password ‘new-password‘ /application/mysql-5.5.52/bin/mysqladmin -u root -h db01 password ‘new-password‘ Alternatively you can run: /application/mysql-5.5.52/bin/mysql_secure_installation which will also give you the option of removing the test databases and anonymous user created by default. This is strongly recommended for production servers. See the manual for more instructions. You can start the MySQL daemon with: cd /application/mysql-5.5.52 ; /application/mysql-5.5.52/bin/mysqld_safe & You can test the MySQL daemon with mysql-test-run.pl cd /application/mysql-5.5.52/mysql-test ; perl mysql-test-run.pl Please report any problems at http://bugs.mysql.com/
上面有两个OK就表示初始化数据库完成
9、配置启动MySQL
[[email protected] scripts]# cd [[email protected] ~]# cp /application/mysql/support-files/mysql.server /etc/init.d/mysqld [[email protected]01 ~]# chmod +x /etc/init.d/mysqld [[email protected] ~]# sed -i ‘s#/usr/local/mysql#/application/mysql#g‘ /application/mysql/bin/mysqld_safe /etc/init.d/mysqld [[email protected] ~]# /etc/init.d/mysqld start Starting MySQL... SUCCESS!
启动报错
#/etc/init.d/mysqld start
(1)启动文件保存
/etc/init.d/mysqld: line 276: cd: /usr/local/mysql: 没有那个文件或目录 Starting MySQL ERROR! Couldn‘t find MySQL server (/usr/local/mysql/bin/mysqld_safe)
解决:
sed -i ‘s#/usr/local/mysql#/application/mysql#g‘ /application/mysql/bin/mysqld_safe /etc/init.d/mysqld
(2)MySQL启动报错
/etc/init.d/mysqld start 报错: [[email protected] mysql]# /etc/init.d/mysqld start Starting MySQL.. ERROR! The server quit without updating PID file (/var/lib/mysql/mysql.pid).
问题所在:mysql初始化出错
解决:
1.清空数据data目录
rm -f /application/mysql/data/*
2.重新初始化mysql
/application/mysql/scripts/mysql_install_db --user=mysql --basedir=/application/mysql --datadir=/application/mysql/data/
3.接着从初始化步骤后的步骤重新操作
netstat -lntup|grep mysql
10、加入开机自启动
[[email protected] ~]# chkconfig mysqld on [[email protected] ~]# chkconfig --list mysqld mysqld 0:关闭 1:关闭 2:启用 3:启用 4:启用 5:启用 6:关闭
11、检查端口
[[email protected] ~]# netstat -lntup | grep 3306 tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 21333/mysqld
到这里MySQL数据库就安装完毕啦 O(∩_∩)O~~!!!
本文出自 “炫维” 博客,请务必保留此出处http://xuanwei.blog.51cto.com/11489734/1881478
以上是关于MySQL5.5.52编译安装的主要内容,如果未能解决你的问题,请参考以下文章
Android 逆向Android 逆向通用工具开发 ( Android 平台运行的 cmd 程序类型 | Android 平台运行的 cmd 程序编译选项 | 编译 cmd 可执行程序 )(代码片段