MySQL5.7安装--二进制方式安装

前端之家收集整理的这篇文章主要介绍了MySQL5.7安装--二进制方式安装前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

操作系统版本: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 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的一个分支,需要卸载

[root@MysqL MysqL]# rpm -qa |grep mariadb

 

(3) 删除/etc/my.cnf文件。该文件类似Oracle的参数文件

[root@MysqL MysqL]# rm /etc/my.cnf
rm: 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| MysqL MysqL: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 MysqL Changing password for user MysqL. New password: BAD PASSWORD: it is too short BAD PASSWORD: is too simple Retype 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]# 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的文件

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/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)设置启动项

bin COPYING data docs include lib man README share support-files [root@MysqL MysqL]# cd ./support-files/MysqL MysqLd_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 start
Starting MysqL.                                            [  OK  ]
 
查看数据库状态
[root@MysqL MysqL]# service MysqLd status MysqL running (39674) [ OK ] # 或者 [root@MysqL MysqL]# ps -ef| MysqL MysqL 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 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

 

安装完成。

猜你在找的MySQL相关文章