Linux下安装MySQL 5.7

本次分享如何在Linux下安装MySQL 5.7
操作系统版本:RedHat/CentOS 6.6 X64
MySQL版本:5.7.11
安装方式:二进制

安装过程:
[ root@gusha2  ~]# mkdir /data/dbwyzc -p
1、创建MySQL安装目录

2、创建一个不允许登录的MySQL用户及组
[ root@gusha2  ~]# groupadd mysql
[ root@gusha2  ~]#  useradd -g mysql -s /sbin/nologin -d /data/mysql mysql
Creating mailbox file: File exists
[ root@gusha2  ~]# id mysql
uid=500(mysql) gid=500(mysql) groups=500(mysql)

3、解压下载下来的MySQL安装包
[ root@gusha2  ~]# mv /root/Desktop/mysql-5.7.11-linux-glibc2.5-x86_64.tar.gz /data/mysql/
[ root@gusha2  ~]# cd /data/mysql/
[ root@gusha2  mysql]# tar xf mysql-5.7.11-linux-glibc2.5-x86_64.tar.gz 
[ root@gusha2  mysql]# ls
mysql-5.7.11-linux-glibc2.5-x86_64  mysql-5.7.11-linux-glibc2.5-x86_64.tar.gz
做个软连接到/usr/local/mysql
[ root@gusha2  mysql]# cd /usr/local/
[ root@gusha2  local]#  ln -s /data/mysql/mysql-5.7.11-linux-glibc2.5-x86_64 mysql
[ root@gusha2  local]# ls -l mysql
lrwxrwxrwx. 1 root root 46 Mar 24 02:43 mysql -> /data/mysql/mysql-5.7.11-linux-glibc2.5-x86_64

4、创建datadir及日志存储路径
[ root@gusha2  local]# cd /data/dbwyzc/
[ root@gusha2  dbwyzc]# ls
[ root@gusha2  dbwyzc]# mkdir {data,logs}

5、授权
[ root@gusha2  dbwyzc]# chown -R mysql.mysql /data/dbwyzc/
[ root@gusha2  dbwyzc]# chown -R mysql.mysql /usr/local/mysql/

6、因为是选择从MySQL压缩包中初始化MySQL,不是直接安装MySQL,需手动解决找不到mysql命令的问题
[ root@gusha2  dbwyzc]#  echo 'export PATH=$PATH:/usr/local/mysql/bin' >> /etc/profile
[ root@gusha2  dbwyzc]# source !$
source /etc/profile

7、关闭防火墙及selinux
[ root@gusha2  dbwyzc]# chkconfig iptables off
[ root@gusha2  dbwyzc]# vi /etc/sysconfig/selinux 
SELINUX=disabled

8、修改my.cnf
[ root@gusha2  dbwyzc]# vi /etc/my.cnf 
[client]
port=3306
socket=/tmp/mysql.sock

[mysqld]
user=mysql
basedir=/usr/local/mysql
datadir=/data/dbwyzc/data
socket=/tmp/mysql.sock
log-error=/data/dbwyzc/logs/mysqld.log
pid-file=/data/dbwyzc/mysqld.pid

9、初始化MySQL
在5.7中,推荐使用mysqld --initialize对数据库进行初始化(mysql_install_db已经不再推荐使用),在初始化时如果加上--initialize-insecure,则会创建空密码的  root@localhost  账号,否则会创建带密码的  root@localhost  账号,密码直接写在 log-error 日志文件中
[ root@gusha2  mysql]# cd bin/
[ root@gusha2  bin]#  mysqld --defaults-file=/etc/my.cnf --user=mysql --initialize --initialize-insecure
[ root@gusha2  bin]# ls /data/dbwyzc/data/
auto.cnf        ibdata1      ib_logfile1  performance_schema
ib_buffer_pool  ib_logfile0  mysql        sys
[ root@gusha2  bin]# ls /data/dbwyzc/logs/
mysqld.log
[ root@gusha2  bin]# cat /data/dbwyzc/logs/mysqld.log 
2016-03-23T20:45:41.774933Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2016-03-23T20:45:43.665168Z 0 [Warning] InnoDB: New log files created, LSN=45790
2016-03-23T20:45:43.939168Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2016-03-23T20:45:44.025867Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 368bbcd5-f138-11e5-aad0-000c29f650ca.
2016-03-23T20:45:44.029664Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2016-03-23T20:45:44.031662Z 1 [Warning]  root@localhost  is created with an empty password ! Please consider switching off the --initialize-insecure option.

10、添加使用service快速启动MySQL
[ root@gusha2  bin]# cd ../
[ root@gusha2  mysql]#  ls support-files/
magic  my-default.cnf  mysqld_multi.server  mysql-log-rotate  mysql.server
[ root@gusha2  mysql]# cp support-files/mysql.server /etc/init.d/mysql
[ root@gusha2  mysql]# service mysql start
Starting MySQL.                                            [  OK  ]

之后给root用户设置个密码:
[ root@gusha2  mysql]# mysql

mysql> set password=password('mysql123');

不要被上面繁琐的操作步骤所迷惑,这种方法是我们搭建测试环境及MySQL多实例环境用到的最多的一种安装方法,其操作对于熟练掌握Linux简单命令的人来说已经非常简单了,最重要的是,使用二进制的安装方法,可以让我们在安装MySQL的过程中了解到MySQL各文件的位置、作用、MySQL初始化的时候都做了哪些工作等。

更多精彩MySQL内容 请关注我哦!


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值