
*** 作系统版本:redhat 6.7 64位
[root@MysqL ~]# cat /etc/redhat-release
Red Hat Enterprise linux Server release 6.7 (Santiago)
数据库版本:MysqL5.7
下载地址: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 MysqLMysqL-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的一个分支,需要卸载
[root@MysqL MysqL]# rpm -qa |grep mariadb
(3) 删除/etc/my.cnf文件。该文件类似Oracle的参数文件
[root@MysqL MysqL]# rm /etc/my.cnfrm: cannot remove `/etc/my.cnf': No such file or directory
(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库具有依赖性 。
# search [root@MysqL MysqL]# search libnuma# library[root@MysqL MysqL]# install libnuma
(5)创建MysqL用户来管理数据库
cat /etc/passwd| MysqLMysqL:x:27:27:MysqL Server:/var/lib/MysqL:/bin/bash[root@MysqL MysqL]# cat /etc/group |27:如果没有,则创建用户组和用户
[root@MysqL MysqL]# groupadd MysqL[root@MysqL MysqL]# useradd -g MysqL MysqL修改MysqL用户密码:
passwd MysqLChanging password for user MysqL.New password: BAD PASSWORD: it is too shortBAD PASSWORD: is too simpleRetype new password: passwd: all authentication tokens updated successfully.
(二)安装MysqL数据库
MysqL安装路径:/usr/local/MysqL/
数据存放位置::/usr/local/MysqL/data
(1)解压MysqL安装包
tar -xzvf MysqL-24-linux-glibc2.12-x86_64.tar.gz(2)将解压后的文件拷贝到安装路径下
mv MysqL-12-x86_64 /usr/local/MysqL/(3)修改文件的权限
[root@MysqL MysqL]# cd /usr/local/[root@MysqL local]# lsbin etc games include lib lib64 libexec MysqL sbin share src[root@MysqL local]# chown -R MysqL MysqL/chgrp -R MysqL MysqL/
(4)创建存放data的文件夹
mkdir data[root@MysqL MysqL]# chown -R MysqL:MysqL data(5)在/etc下创建MysqL的参数文件my.cnf
[root@MysqL etc]# vim my.cnf
[MysqL]# 设置MysqL客户端默认字符集default-character-set=utf8[MysqLd]skip-name-resolve# 设置3306端口port = 3306 # 设置MysqL的安装目录basedir=/usr/local/MysqL# 设置MysqL数据库的数据的存放目录datadir=/usr/local/MysqL/data# 允许最大连接数max_connections=200# 服务端使用的字符集默认为8比特编码的latin1字符集character-set-server=utf8# 创建新表时将使用的默认存储引擎default-storage-engine=INNODB lower_case_table_names=max_allowed_packet=16M(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/data2019-04-20 22:17:08 [WARNING] MysqL_install_db is deprecated. Please consIDer switching to MysqLd --initialize14 [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)设置启动项
bin copYING data docs include lib man README share support-files[root@MysqL MysqL]# cd ./support-files/MysqLMysqLd_multi.server MysqL-log-rotate MysqL.server [root@MysqL MysqL]# cp ./support-files/MysqL.server /etc/init.d/MysqLd[root@MysqL MysqL]# chown 777 /etc/my.cnf[root@MysqL MysqL]# chmod a+x /etc/init.d/MysqLd(7)开启数据库
[root@MysqL MysqL]# /etc/init.d/MysqLd startStarting MysqL. [ OK ]查看数据库状态[root@MysqL MysqL]# service MysqLd statusMysqL running (39674) [ OK ]# 或者[root@MysqL MysqL]# ps -ef| MysqLMysqL 39674 1 0 53 pts/0 00:01 /usr/local/MysqL/bin/MysqLd --basedir=/usr/local/MysqL --datadir=/usr/local/MysqL/data --plugin-dir=/usr/local/MysqL/lib/plugin --log-error=MysqL.err --pID-file=/usr/local/MysqL/data/MysqL.pID --port=root 40719 3339 23:13 pts/00 grep MysqL
(8)修改数据库的初始root密码
(8.1)查看初始密码
cat /root/.MysqL_secret # Password set for user root@localhost' at 08 bkro9k_?=jrM(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 2Server version: 24MysqL> 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]# profileexport PATH=/usr/local/MysqL/bin:$PATH#使环境变量生效[root@MysqL MysqL]# source /etc/profile
安装完成。
总结以上是内存溢出为你收集整理的MySQL5.7安装--二进制方式安装全部内容,希望文章能够帮你解决MySQL5.7安装--二进制方式安装所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)