操作系统版本:redhat 6.7 64位
[root@MysqL ~]# cat /etc/redhat-release
Red Hat Enterprise Linux Server release 6.7 (Santiago)
下载地址:https://downloads.mysql.com/archives/community/
我下载的包为:MysqL-5.7.24-linux-glibc2.12-x86_64.tar.gz
(一)安装前的准备
(1)查看服务器上是否已经安装了MysqL。RedHat Linux系统安装时,如果选择了MysqL数据库,那么服务器上会存在MysqL数据库,需要先卸载。
# 查看是否存在MysqL安装包 [root@MysqL etc]# rpm -qa| grep MysqL MysqL-community-common-5.7.21-1.el7.x86_64 # 如果存在,需要先卸载 [root@MysqL etc]# rpm -e MysqL-community-common-1.el7.x86_64
(2)查看服务器上是否存在mariadb数据库。mariadb是MysqL的一个分支,需要卸载
(3) 删除/etc/my.cnf文件。该文件类似Oracle的参数文件
(4)依赖包安装
MysqL对libaio 库有依赖性。如果未在本地安装该库,则数据目录初始化和随后的服务器启动步骤将失败
# search for info [root@MysqL MysqL]# yum search libaio # install library [root@MysqL MysqL]# yum install libaio
对于MysqL 5.7.19和更高版本:通用Linux版本中增加了对非统一内存访问(NUMA)的支持,该版本现在对libnuma库具有依赖性 。
数据存放位置::/usr/local/MysqL/data
(1)解压MysqL安装包
(2)将解压后的文件拷贝到安装路径下
[root@MysqL MysqL]# cd /usr/local/ [root@MysqL local]# ls bin etc games include lib lib64 libexec MysqL sbin share src [root@MysqL local]# chown -R MysqL MysqL/chgrp -R MysqL MysqL/
(4)创建存放data的文件夹
[root@MysqL etc]# vim my.cnf
(6)安装数据库
[root@MysqL bin]# pwd /usr/local/MysqL/bin [root@MysqL bin]# ./MysqL_install_db --user=MysqL --basedir=/usr/local/MysqL/ --datadir=/usr/local/MysqL/data 2019-04-20 22:17:08 [WARNING] MysqL_install_db is deprecated. Please consider switching to MysqLd --initialize 14 [WARNING] The bootstrap log isnt empty: 14 [WARNING] 04-20T14:08.662276Z 0 [Warning] --bootstrap is deprecated. Please consider using 08.663008Z 0 [Warning] Changed limits: max_open_files: 1024 (requested 5000) 08.663018Z 0 [Warning] Changed limits: table_open_cache: 407 (requested 2000)
2020年3月28日补充:
在MysqL5.7中,使用“MysqL_install_db”脚本来初始化数据库已经不被推荐,建议使用如下方式:
/usr/local/MysqL/bin/MysqLd --defaults-file=/MysqL/3306/my.cnf --initialize --basedir=/usr/local/MysqL/ --datadir=/MysqL/3306/data
(6)设置启动项
(7)开启数据库
查看数据库状态
(8.1)查看初始密码
(8.2)使用初始密码登录数据库,修改初始密码为123456
[root@MysqL MysqL]# MysqL -uroot -p Enter password: Welcome to the MysqL monitor. Commands end with ; or \g. Your MysqL connection id is 2 Server version: 24 MysqL> set password=password(123456'); Query OK,0 rows affected,1 warning (0.00 sec)
(9)确认数据库状态,运行正常
MysqL> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | MysqL | | performance_schema | | sys | +--------------------+ 4 rows in set (0.00 sec)
(10)环境变量设置
在安装之后,如果我们想要调用到MysqL安装基本目录下面的MysqL工具,还需设定环境变量
[root@MysqL MysqL]# profile export PATH=/usr/local/MysqL/bin:$PATH #使环境变量生效 [root@MysqL MysqL]# source /etc/profile
安装完成。