安装mysql5.6


一、上传文件到/usr/local/src/

[root@localhost src]# ls
mysql-5.6.43-linux-glibc2.12-x86_64.tar.gz

通常会将一些安装包放在/usr/local/src目录下,这样方便管理。

二、解压文件

  1. 解压压缩包
[root@localhost src]# tar -zxvf mysql-5.6.43-linux-glibc2.12-x86_64.tar.gz 
[root@localhost src]# ls
mysql-5.6.43-linux-glibc2.12-x86_64  mysql-5.6.43-linux-glibc2.12-x86_64.tar.gz
  1. 解压的文件移动到/usr/local目录下,并重新命名mysql
[root@localhost src]# mv mysql-5.6.43-linux-glibc2.12-x86_64 /usr/local/mysql
[root@localhost src]# ls
mysql-5.6.43-linux-glibc2.12-x86_64.tar.gz
[root@localhost src]# ls /usr/local/
bin  etc  games  include  lib  lib64  libexec  mysql  sbin  share  src

这样做方便管理,并不是硬性要求

三、创建用户

1.创建mysql用户

[root@localhost src]# useradd -s /sbin/nologin mysql

2、创建数据目录

[root@localhost src]# mkdir -p /data/mysql

3、为数据目录赋予mysql的权限

[root@localhost src]# chown -R mysql:mysql /data/mysql/

四、脚本安装mysql

1、运行脚本

[root@localhost src]# cd /usr/local/mysql/
[root@localhost mysql]# ls
bin  COPYING  data  docs  include  lib  man  mysql-test  README  scripts  share  sql-bench  support-files
[root@localhost mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql/
-bash: ./scripts/mysql_install_db: /usr/bin/perl: bad interpreter: No such file or directory

运行脚本会有报错,意思是缺少Perl环境。

[root@localhost mysql]# head 5  scripts/mysql_install_db 
head: cannot open ‘5for reading: No such file or directory
==> scripts/mysql_install_db <==
#!/usr/bin/perl
# -*- cperl -*-
#
# Copyright (c) 2007, 2017, Oracle and/or its affiliates. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,

查看脚本前半部分发现有一句/usr/bin/perl,说明该脚本想要则需要Perl的环境。

2、安装Perl后运行脚本安装mysql

[root@localhost mysql]# yum list |grep '^perl'
perl-Module-Install.noarch                  1.06-4.el7                 base 
[root@localhost mysql]# yum install -y perl-Module-Install
[root@localhost mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql/

五、配置文件

1、复制配置文件到/etc/目录下

[root@localhost support-files]# cp my-default.cnf /etc/my.cnf
cp: overwrite ‘/etc/my.cnf’? y

这里直接覆盖掉系统自带的文件

[root@localhost support-files]# cp mysql.server /etc/init.d/mysqld
[root@localhost support-files]# chmod  755 /etc/init.d/mysqld 

755:u–rwx g–rx o–rx

2、修改配置文件

[root@localhost support-files]# vi /etc/my.cnf
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html
# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL.

[mysqld]

# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M

# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin

# These are commonly set, remove the # and set as required.
# basedir = .....   //改为basedir = /usr/local/mysql
# datadir = .....   //改为datadir = /data/mysql
# port = .....      //改为port = 3306
# server_id = ..... //改为server_id = 115
# socket = .....    //改为socket = /tmp/mysql.sock

# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
[root@localhost support-files]# vi /etc/init.d/mysqld 
basedir=      //找到该字段
datadir=
//修改为
basedir=/usr/local/mysql
datadir=/data/mysql

六、启动mysql

1、将mysql加入服务列表

[root@localhost support-files]# chkconfig --add mysqld
[root@localhost support-files]# chkconfig mysqld on

2、启动mysql服务

[root@localhost support-files]# service mysqld start
Starting MySQL.Logging to '/data/mysql/localhost.localdomain.err'.
 SUCCESS! 

七、将mysql加入系统环境变量

[root@localhost support-files]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
[root@localhost support-files]# export PATH=$PATH:/usr/local/mysql/bin/
[root@localhost support-files]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/usr/local/mysql/bin/

[root@localhost support-files]# vim /etc/profile
//在文件的最后一行插入
 export PATH=$PATH:/usr/local/mysql/bin/
[root@localhost support-files]# source /etc/profile

3、登录mysql(初始没有设置密码,直接登入就可了)

[root@localhost support-files]# mysql -uroot
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.6.43 MySQL Community Server (GPL)

Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值