CentOS-6 MySQL-5.7.21安装部署

  • 2
  • 5,412 views
  • A+
所属分类:MySQL

提示:因服务器环境不一样,安装过程中可能会有差异

  

MySQL5.7.21官网下载地址:

    https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.21-linux-glibc2.12-x86_64.tar.gz

MySQL5.7.21我的网站下载:

    https://www.linuxgogo.com/repodata/Binary/CentOS_6/MySQL/

 

本文安装方法:二进制包安装

  

1. 下载 mysql-5.7 包并解压

  1. [root@linux-node2 soft]# ll  
  2. total 626760  
  3. drwxr-xr-x 9 root root       120 Jan 18 17:27 mysql-5.7.21-linux-glibc2.12-x86_64  
  4. -rw-r--r-- 1 root root 641798603 Dec 28 11:20 mysql-5.7.21-linux-glibc2.12-x86_64.tar.gz  

 

2. 根据你的要求创建软连接或者不创建,随意,这里我把软连接放在/usr/local下

  1. ln -s /home/soft/mysql-5.7.21-linux-glibc2.12-x86_64 /usr/local/mysql  

 

3. 创建 mysql 用户

  1. useradd -M mysql -s /sbin/nologin  

 

4. 创建相关目录并授权

  1. mkdir /usr/local/mysql/{data,logs,tmp}  
  2. chown -R mysql.mysql /usr/local/mysql/    #对mysql源目录和软连接目录都要授权  

 

5. 将mysql命令加入全局环境变量

  1. [root@linux-node2 ~]# echo 'PATH=/usr/local/mysql/bin:$PATH' >>/etc/profile  
  2. [root@linux-node2 ~]# source /etc/profile  

 

6. 初始化(进入mysql的bin目录下使用mysqld进行初始化,如果这儿没有密码可以去mysql日志文件去找),这也是5.7以后的mysql对以往数据库最大的区别。

  1. [root@linux-node2 ~]# cd /usr/local/mysql/  
  2. [root@linux-node2 mysql]# mysqld --initialize --datadir=/usr/local/mysql/data \  
  3. --basedir=/usr/local/mysql/ --user=mysql  
  4. 2018-01-26T06:18:25.778235Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).  
  5. 2018-01-26T06:18:25.919777Z 0 [Warning] InnoDB: New log files created, LSN=45790  
  6. 2018-01-26T06:18:25.940882Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.  
  7. 2018-01-26T06:18:25.995387Z 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: b7e1f094-0260-11e8-a6a2-000c296a6851.  
  8. 2018-01-26T06:18:25.997392Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.  
  9. 2018-01-26T06:18:25.998200Z 1 [Note] A temporary password is generated for root@localhost: C6bgumDduV(v  

  

注意:初始化数据库使用参数 --initialize 会赋予 mysql 用户 root@localhost 一个随机密码,我这里是:C6bgumDduV(v,这与以往的mysql不一样,启动数据库厚必须修改密码才可以对数据库进行增删改查的操作。 

  

如果想使用空密码则使用参数--initialize-insecure (建议空密码,安装好之后自己直接设置密码即可)

  1. mysqld --initialize-insecure --user=mysql \  
  2. --datadir=/usr/local/mysql/data  --basedir=/usr/local/mysql/  

官方文档:https://dev.mysql.com/doc/refman/5.7/en/data-directory-initialization-mysqld.html

 

安装报错记录:在初始化时遇见报错,缺少 libaio 共享库,报错如下:

  1. mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such f......  

 

解决办法:yum下载 libaio 共享库即可

  1. yum install -y libaio  #安装后再次初始化即可  

 

7. 如果 /etc/ 下没有my.cnf 则自己准备一份mysql的配置文件my.cnf放到/etc下 

  

8. 启动数据库

  1. [root@linux-node2 mysql]# mysqld --user=mysql  &  
  2. [root@linux-node2 mysql]# netstat -lntup|grep 3306  

 

9. 修改数据库密码

  1. [root@linux-node2 mysql]# ./bin/mysqladmin -uroot -p password "123456"   
  2. Enter password: C6bgumDduV(v      #输入现在的mysql密码  

 

10. 登陆数据库

  1. [root@linux-node2 ~]# mysql -uroot -p123456  
  2. mysql: [Warning] Using a password on the command line interface can be insecure.  
  3. Welcome to the MySQL monitor.  Commands end with ; or \g.  
  4. Your MySQL connection id is 7  
  5. Server version: 5.7.21 MySQL Community Server (GPL)  
  6.   
  7. Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.  
  8.   
  9. Oracle is a registered trademark of Oracle Corporation and/or its  
  10. affiliates. Other names may be trademarks of their respective  
  11. owners.  
  12.   
  13. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.  
  14.   
  15. mysql>  

  

11. 对数据库启停命令优化,在 msyql/support-files/ 下的 mysql.server 是 mysql 的一个启停脚本,里面的默认路径就是/usr/local/,我这里不需要改,如果你的 mysql 不是放在 /usr/local 下,该脚本预留了很多变量,其中就有 basedir datadir ,在里面写上 mysql 的家目录和数据目录即可,然后加入到 chkconfig 进行管理,这里就不写具体命令。

   

  

zhaoyulin

发表评论取消回复

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

目前评论:2   其中:访客  0   博主  0

    • 匿名 匿名 2

      支持一下

        • zhaoyulin zhaoyulin Admin

          @匿名 :idea: