• 使用二进制安装包的方式单机部署MySQL8.0.13


               使用二进制安装包的方式单机部署MySQL8.0.13

                                           作者:尹正杰 

    版权声明:原创作品,谢绝转载!否则将追究法律责任。

      关于MySQL的介绍我这里就不多做赘述了,如何下载MySQL详情请参考:MySQL入门介绍(mysql-8.0.13)。本篇博客默认你已经将MySQL二进制tar包下载好并上传到服务器上了。

    一.使用默认的安装路径部署MySQL服务

    1>.安装上传工具

    [root@node101 ~]# yum -y install lrzsz

    2>.上传MySQL的二进制安装包到服务器上

    [root@node101 ~]# cd /usr/local/
    [root@node101 local]# 
    [root@node101 local]# ls
    bin  etc  games  include  lib  lib64  libexec  sbin  share  src
    [root@node101 local]# 
    [root@node101 local]# rz 
    rz waiting to receive.
    开始 zmodem 传输。  按 Ctrl+C 取消。
      100%  384621 KB 5827 KB/s 00:01:06       0 Errorss.xz...
    
    [root@node101 local]# 
    [root@node101 local]# ls
    bin  etc  games  include  lib  lib64  libexec  mysql-8.0.13-linux-glibc2.12-x86_64.tar.xz  sbin  share  src
    [root@node101 local]# 

    3>.在“/usr/local"目录进行解压操作并创建符号链接

    [root@node101 local]# ll
    total 384624
    drwxr-xr-x. 2 root root         6 Aug 12  2015 bin
    drwxr-xr-x. 2 root root         6 Aug 12  2015 etc
    drwxr-xr-x. 2 root root         6 Aug 12  2015 games
    drwxr-xr-x. 2 root root         6 Aug 12  2015 include
    drwxr-xr-x. 2 root root         6 Aug 12  2015 lib
    drwxr-xr-x. 2 root root         6 Aug 12  2015 lib64
    drwxr-xr-x. 2 root root         6 Aug 12  2015 libexec
    -rw-r--r--. 1 root root 393852364 Jan 15 05:10 mysql-8.0.13-linux-glibc2.12-x86_64.tar.xz
    drwxr-xr-x. 2 root root         6 Aug 12  2015 sbin
    drwxr-xr-x. 5 root root        46 Jan 15 05:59 share
    drwxr-xr-x. 2 root root         6 Aug 12  2015 src
    [root@node101 local]# 
    [root@node101 local]# 
    [root@node101 local]# tar -xf mysql-8.0.13-linux-glibc2.12-x86_64.tar.xz 
    [root@node101 local]# 
    [root@node101 local]# ll
    total 384628
    drwxr-xr-x. 2 root root         6 Aug 12  2015 bin
    drwxr-xr-x. 2 root root         6 Aug 12  2015 etc
    drwxr-xr-x. 2 root root         6 Aug 12  2015 games
    drwxr-xr-x. 2 root root         6 Aug 12  2015 include
    drwxr-xr-x. 2 root root         6 Aug 12  2015 lib
    drwxr-xr-x. 2 root root         6 Aug 12  2015 lib64
    drwxr-xr-x. 2 root root         6 Aug 12  2015 libexec
    drwxr-xr-x. 9 root root      4096 Jan 15 15:46 mysql-8.0.13-linux-glibc2.12-x86_64
    -rw-r--r--. 1 root root 393852364 Jan 15 05:10 mysql-8.0.13-linux-glibc2.12-x86_64.tar.xz
    drwxr-xr-x. 2 root root         6 Aug 12  2015 sbin
    drwxr-xr-x. 5 root root        46 Jan 15 05:59 share
    drwxr-xr-x. 2 root root         6 Aug 12  2015 src
    [root@node101 local]# 
    [root@node101 local]# tar -xf mysql-8.0.13-linux-glibc2.12-x86_64.tar.xz
    [root@node101 local]# ll
    total 384628
    drwxr-xr-x. 2 root root         6 Aug 12  2015 bin
    drwxr-xr-x. 2 root root         6 Aug 12  2015 etc
    drwxr-xr-x. 2 root root         6 Aug 12  2015 games
    drwxr-xr-x. 2 root root         6 Aug 12  2015 include
    drwxr-xr-x. 2 root root         6 Aug 12  2015 lib
    drwxr-xr-x. 2 root root         6 Aug 12  2015 lib64
    drwxr-xr-x. 2 root root         6 Aug 12  2015 libexec
    drwxr-xr-x. 9 root root      4096 Jan 15 15:46 mysql-8.0.13-linux-glibc2.12-x86_64
    -rw-r--r--. 1 root root 393852364 Jan 15 05:10 mysql-8.0.13-linux-glibc2.12-x86_64.tar.xz
    drwxr-xr-x. 2 root root         6 Aug 12  2015 sbin
    drwxr-xr-x. 5 root root        46 Jan 15 05:59 share
    drwxr-xr-x. 2 root root         6 Aug 12  2015 src
    [root@node101 local]# 
    [root@node101 local]# 
    [root@node101 local]# ln -s /usr/local/mysql-8.0.13-linux-glibc2.12-x86_64 /usr/local/mysql
    [root@node101 local]# 
    [root@node101 local]# ll
    total 384628
    drwxr-xr-x. 2 root root         6 Aug 12  2015 bin
    drwxr-xr-x. 2 root root         6 Aug 12  2015 etc
    drwxr-xr-x. 2 root root         6 Aug 12  2015 games
    drwxr-xr-x. 2 root root         6 Aug 12  2015 include
    drwxr-xr-x. 2 root root         6 Aug 12  2015 lib
    drwxr-xr-x. 2 root root         6 Aug 12  2015 lib64
    drwxr-xr-x. 2 root root         6 Aug 12  2015 libexec
    lrwxrwxrwx. 1 root root        46 Jan 15 15:48 mysql -> /usr/local/mysql-8.0.13-linux-glibc2.12-x86_64
    drwxr-xr-x. 9 root root      4096 Jan 15 15:46 mysql-8.0.13-linux-glibc2.12-x86_64
    -rw-r--r--. 1 root root 393852364 Jan 15 05:10 mysql-8.0.13-linux-glibc2.12-x86_64.tar.xz
    drwxr-xr-x. 2 root root         6 Aug 12  2015 sbin
    drwxr-xr-x. 5 root root        46 Jan 15 05:59 share
    drwxr-xr-x. 2 root root         6 Aug 12  2015 src
    [root@node101 local]# 
    创建软连接([root@node101 local]# ln -s /usr/local/mysql-8.0.13-linux-glibc2.12-x86_64 /usr/local/mysql)
    [root@node101 local]# du -h --max-depth=1
    0       ./bin
    0       ./etc
    0       ./games
    0       ./include
    0       ./lib
    0       ./lib64
    0       ./libexec
    0       ./sbin
    8.0K    ./share
    0       ./src
    2.0G    ./mysql-8.0.13-linux-glibc2.12-x86_64    #加压后的大小是2个G
    2.3G    .
    [root@node101 local]# 
    [root@node101 local]# 

    4>.MySQL各个目录功能

    [root@node101 local]# ll mysql/
    total 452
    drwxr-xr-x.  2 root root    4096 Jan 15 15:46 bin               #存放MySQL可执行的脚本
    drwxr-xr-x.  2 root root      82 Jan 15 15:46 docs              #存放文档信息
    drwxr-xr-x.  3 root root    4096 Jan 15 15:44 include            #由于MySQL是C和C++编写的,因次我们会在该目录下看到一些以"*.h”的头文件信息
    drwxr-xr-x.  6 root root    4096 Jan 15 15:46 lib               #存放依赖包
    -rw-r--r--.  1 7161 31415 335809 Oct  7 01:44 LICENSE
    -rw-r--r--.  1 7161 31415 101807 Oct  7 01:44 LICENSE.router
    drwxr-xr-x.  4 root root      28 Jan 15 15:44 man               #存放man帮助的信息
    -rw-r--r--.  1 7161 31415    687 Oct  7 01:44 README
    -rw-r--r--.  1 7161 31415    700 Oct  7 01:44 README.router
    drwxr-xr-x. 28 root root    4096 Jan 15 15:46 share             #存放支持的字符集信息以及一些错误信息
    drwxr-xr-x.  2 root root      86 Jan 15 15:46 support-files        #存放MySQL服务的管理脚本,比如我们想要将MySQL变成一个Linux开机自启动服务时,就得使用该目录下的mysql.service脚本!
    [root@node101 local]# 
    [root@node101 local]# 

    5>.创建默认的数据目录

    [root@node101 local]# mkdir /usr/local/mysql/data
    [root@node101 local]# 
    [root@node101 local]# ll mysql/
    total 452
    drwxr-xr-x.  2 root root    4096 Jan 15 15:46 bin
    drwxr-xr-x.  2 root root       6 Jan 15 16:04 data
    drwxr-xr-x.  2 root root      82 Jan 15 15:46 docs
    drwxr-xr-x.  3 root root    4096 Jan 15 15:44 include
    drwxr-xr-x.  6 root root    4096 Jan 15 15:46 lib
    -rw-r--r--.  1 7161 31415 335809 Oct  7 01:44 LICENSE
    -rw-r--r--.  1 7161 31415 101807 Oct  7 01:44 LICENSE.router
    drwxr-xr-x.  4 root root      28 Jan 15 15:44 man
    -rw-r--r--.  1 7161 31415    687 Oct  7 01:44 README
    -rw-r--r--.  1 7161 31415    700 Oct  7 01:44 README.router
    drwxr-xr-x. 28 root root    4096 Jan 15 15:46 share
    drwxr-xr-x.  2 root root      86 Jan 15 16:03 support-files
    [root@node101 local]# 
    如下图所示,我们需要创建mysql默认的数据目录([root@node101 local]# mkdir /usr/local/mysql/data)

    6>.创建mysql用户(不建议使用root用户直接启动该服务)

    [root@node101 local]# useradd mysql                #这条命令会默认帮我们创建一个mysql用户,并将该用户加入一个同名的组中
    [root@node101 local]# 
    [root@node101 local]# id mysql
    uid=1001(mysql) gid=1001(mysql) groups=1001(mysql)
    [root@node101 local]# 
    [root@node101 local]# 
    [root@node101 local]# pwd
    /usr/local
    [root@node101 local]# 
    [root@node101 local]# ll
    total 384628
    drwxr-xr-x.  2 root root         6 Aug 12  2015 bin
    drwxr-xr-x.  2 root root         6 Aug 12  2015 etc
    drwxr-xr-x.  2 root root         6 Aug 12  2015 games
    drwxr-xr-x.  2 root root         6 Aug 12  2015 include
    drwxr-xr-x.  2 root root         6 Aug 12  2015 lib
    drwxr-xr-x.  2 root root         6 Aug 12  2015 lib64
    drwxr-xr-x.  2 root root         6 Aug 12  2015 libexec
    lrwxrwxrwx.  1 root root        46 Jan 15 15:48 mysql -> /usr/local/mysql-8.0.13-linux-glibc2.12-x86_64
    drwxr-xr-x. 10 root root      4096 Jan 15 16:04 mysql-8.0.13-linux-glibc2.12-x86_64
    -rw-r--r--.  1 root root 393852364 Jan 15 05:10 mysql-8.0.13-linux-glibc2.12-x86_64.tar.xz
    drwxr-xr-x.  2 root root         6 Aug 12  2015 sbin
    drwxr-xr-x.  5 root root        46 Jan 15 05:59 share
    drwxr-xr-x.  2 root root         6 Aug 12  2015 src
    [root@node101 local]# 
    [root@node101 local]# chown mysql:mysql mysql
    [root@node101 local]# 
    [root@node101 local]# ll
    total 384628
    drwxr-xr-x.  2 root  root          6 Aug 12  2015 bin
    drwxr-xr-x.  2 root  root          6 Aug 12  2015 etc
    drwxr-xr-x.  2 root  root          6 Aug 12  2015 games
    drwxr-xr-x.  2 root  root          6 Aug 12  2015 include
    drwxr-xr-x.  2 root  root          6 Aug 12  2015 lib
    drwxr-xr-x.  2 root  root          6 Aug 12  2015 lib64
    drwxr-xr-x.  2 root  root          6 Aug 12  2015 libexec
    lrwxrwxrwx.  1 root  root         46 Jan 15 15:48 mysql -> /usr/local/mysql-8.0.13-linux-glibc2.12-x86_64
    drwxr-xr-x. 10 mysql mysql      4096 Jan 15 16:04 mysql-8.0.13-linux-glibc2.12-x86_64
    -rw-r--r--.  1 root  root  393852364 Jan 15 05:10 mysql-8.0.13-linux-glibc2.12-x86_64.tar.xz
    drwxr-xr-x.  2 root  root          6 Aug 12  2015 sbin
    drwxr-xr-x.  5 root  root         46 Jan 15 05:59 share
    drwxr-xr-x.  2 root  root          6 Aug 12  2015 src
    [root@node101 local]# 
    修改解压包的权限给咱们刚刚创建的mysql用户([root@node101 local]# chown mysql:mysql mysql)

    7>.初始化MySQL数据目录

    [root@node101 ~]# ll /usr/local/mysql/data/
    total 0
    [root@node101 ~]# 
    [root@node101 ~]# cd /usr/local/mysql/bin/
    [root@node101 bin]# 
    [root@node101 bin]# ./mysqld --initialize --user=mysql --datadir /usr/local/mysql/data
    2019-01-16T00:16:37.880029Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it' is deprecated and will be removed in a future release.
    2019-01-16T00:16:37.880151Z 0 [System] [MY-013169] [Server] /usr/local/mysql-8.0.13-linux-glibc2.12-x86_64/bin/mysqld (mysqld 8.0.13) initializing of server in progress as process 41116
    2019-01-16T00:17:05.772135Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: XwRQr7)jF0%M
    2019-01-16T00:17:18.974116Z 0 [System] [MY-013170] [Server] /usr/local/mysql-8.0.13-linux-glibc2.12-x86_64/bin/mysqld (mysqld 8.0.13) initializing of server has completed
    [root@node101 bin]# 
    [root@node101 bin]# 
    [root@node101 bin]# ll /usr/local/mysql/data/
    total 155708
    -rw-r-----. 1 mysql mysql       56 Jan 15 16:17 auto.cnf
    -rw-------. 1 mysql mysql     1676 Jan 15 16:17 ca-key.pem
    -rw-r--r--. 1 mysql mysql     1112 Jan 15 16:17 ca.pem
    -rw-r--r--. 1 mysql mysql     1112 Jan 15 16:17 client-cert.pem
    -rw-------. 1 mysql mysql     1676 Jan 15 16:17 client-key.pem
    -rw-r-----. 1 mysql mysql     5753 Jan 15 16:17 ib_buffer_pool
    -rw-r-----. 1 mysql mysql 12582912 Jan 15 16:17 ibdata1
    -rw-r-----. 1 mysql mysql 50331648 Jan 15 16:17 ib_logfile0
    -rw-r-----. 1 mysql mysql 50331648 Jan 15 16:16 ib_logfile1
    drwxr-x---. 2 mysql mysql        6 Jan 15 16:17 #innodb_temp
    drwxr-x---. 2 mysql mysql     4096 Jan 15 16:17 mysql
    -rw-r-----. 1 mysql mysql 25165824 Jan 15 16:17 mysql.ibd
    drwxr-x---. 2 mysql mysql     4096 Jan 15 16:17 performance_schema
    -rw-------. 1 mysql mysql     1680 Jan 15 16:17 private_key.pem
    -rw-r--r--. 1 mysql mysql      452 Jan 15 16:17 public_key.pem
    -rw-r--r--. 1 mysql mysql     1112 Jan 15 16:17 server-cert.pem
    -rw-------. 1 mysql mysql     1680 Jan 15 16:17 server-key.pem
    drwxr-x---. 2 mysql mysql       27 Jan 15 16:17 sys
    -rw-r-----. 1 mysql mysql 10485760 Jan 15 16:17 undo_001
    -rw-r-----. 1 mysql mysql 10485760 Jan 15 16:17 undo_002
    [root@node101 bin]# 
    [root@node101 bin]# 
    [root@node101 bin]# ./mysqld --initialize --user=mysql --datadir /usr/local/mysql/data

    [root@node101 ~]# cd /usr/local/mysql/data/
    [root@node101 data]# ll
    total 155708
    -rw-r-----. 1 mysql mysql       56 Jan 15 16:12 auto.cnf
    -rw-------. 1 mysql mysql     1680 Jan 15 16:12 ca-key.pem
    -rw-r--r--. 1 mysql mysql     1112 Jan 15 16:12 ca.pem
    -rw-r--r--. 1 mysql mysql     1112 Jan 15 16:12 client-cert.pem
    -rw-------. 1 mysql mysql     1680 Jan 15 16:12 client-key.pem
    -rw-r-----. 1 mysql mysql     5753 Jan 15 16:12 ib_buffer_pool
    -rw-r-----. 1 mysql mysql 12582912 Jan 15 16:12 ibdata1
    -rw-r-----. 1 mysql mysql 50331648 Jan 15 16:12 ib_logfile0
    -rw-r-----. 1 mysql mysql 50331648 Jan 15 16:12 ib_logfile1
    drwxr-x---. 2 mysql mysql        6 Jan 15 16:12 #innodb_temp
    drwxr-x---. 2 mysql mysql     4096 Jan 15 16:12 mysql
    -rw-r-----. 1 mysql mysql 25165824 Jan 15 16:12 mysql.ibd
    drwxr-x---. 2 mysql mysql     4096 Jan 15 16:12 performance_schema
    -rw-------. 1 mysql mysql     1680 Jan 15 16:12 private_key.pem
    -rw-r--r--. 1 mysql mysql      452 Jan 15 16:12 public_key.pem
    -rw-r--r--. 1 mysql mysql     1112 Jan 15 16:12 server-cert.pem
    -rw-------. 1 mysql mysql     1680 Jan 15 16:12 server-key.pem
    drwxr-x---. 2 mysql mysql       27 Jan 15 16:12 sys
    -rw-r-----. 1 mysql mysql 10485760 Jan 15 16:12 undo_001
    -rw-r-----. 1 mysql mysql 10485760 Jan 15 16:12 undo_002
    [root@node101 data]# rm -rf *
    [root@node101 data]# 
    多次初始化失败时,会报错说是数据目录已经有数据了,我们去对应的数据目录将其删除掉即可!

      如果同学们在初始化遇到如下图所示的报错信息,大家不要慌,安装“libaio”依赖包即可:

    [root@node105 data]# ll
    total 0
    [root@node105 data]# 
    [root@node105 data]# pwd
    /yinzhengjie/softwares/mysql-8.0.14-linux-glibc2.12-x86_64/data
    [root@node105 data]# 
    [root@node105 data]# 
    [root@node105 data]# mysqld --initialize --user=mysql --basedir=/yinzhengjie/softwares/mysql-8.0.14-linux-glibc2.12-x86_64 --datadir=/yinzhengjie/softwares/mysql-8.0.14-linux-glibc2.12-x86_64/data &
    [1] 3852
    [root@node105 data]# mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory
    
    [1]+  Exit 127                mysqld --initialize --user=mysql --basedir=/yinzhengjie/softwares/mysql-8.0.14-linux-glibc2.12-x86_64 --datadir=/yinzhengjie/softwares/mysql-8.0.14-linux-glibc2.12-x86_64/data
    [root@node105 data]# 
    [root@node105 data]# 
    [root@node105 data]# 
    [root@node105 data]# yum -y install libaio
    Loaded plugins: fastestmirror
    Loading mirror speeds from cached hostfile
     * base: ftp.sjtu.edu.cn
     * extras: mirror.lzu.edu.cn
     * updates: ftp.sjtu.edu.cn
    Resolving Dependencies
    --> Running transaction check
    ---> Package libaio.x86_64 0:0.3.109-13.el7 will be installed
    --> Finished Dependency Resolution
    
    Dependencies Resolved
    
    ========================================================================================================================================================================================================
     Package                                       Arch                                          Version                                                  Repository                                   Size
    ========================================================================================================================================================================================================
    Installing:
     libaio                                        x86_64                                        0.3.109-13.el7                                           base                                         24 k
    
    Transaction Summary
    ========================================================================================================================================================================================================
    Install  1 Package
    
    Total download size: 24 k
    Installed size: 38 k
    Downloading packages:
    libaio-0.3.109-13.el7.x86_64.rpm                                                                                                                                                 |  24 kB  00:00:00     
    Running transaction check
    Running transaction test
    Transaction test succeeded
    Running transaction
      Installing : libaio-0.3.109-13.el7.x86_64                                                                                                                                                         1/1 
      Verifying  : libaio-0.3.109-13.el7.x86_64                                                                                                                                                         1/1 
    
    Installed:
      libaio.x86_64 0:0.3.109-13.el7                                                                                                                                                                        
    
    Complete!
    [root@node105 data]# 
    [root@node105 data]# 
    [root@node105 data]# 
    [root@node105 data]# mysqld --initialize --user=mysql --basedir=/yinzhengjie/softwares/mysql-8.0.14-linux-glibc2.12-x86_64 --datadir=/yinzhengjie/softwares/mysql-8.0.14-linux-glibc2.12-x86_64/data &
    [1] 3858
    [root@node105 data]# 
    [root@node105 data]# 
    [root@node105 data]# 
    [root@node105 data]# 2019-01-22T14:44:52.845268Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it' is deprecated and will be removed in a future release.
    2019-01-22T14:44:52.845381Z 0 [System] [MY-013169] [Server] /yinzhengjie/softwares/mysql-8.0.14-linux-glibc2.12-x86_64/bin/mysqld (mysqld 8.0.14) initializing of server in progress as process 3858
    2019-01-22T14:45:07.024823Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: d_0_b?C%8?2Y
    2019-01-22T14:45:11.392014Z 0 [System] [MY-013170] [Server] /yinzhengjie/softwares/mysql-8.0.14-linux-glibc2.12-x86_64/bin/mysqld (mysqld 8.0.14) initializing of server has completed
    
    [1]+  Done                    mysqld --initialize --user=mysql --basedir=/yinzhengjie/softwares/mysql-8.0.14-linux-glibc2.12-x86_64 --datadir=/yinzhengjie/softwares/mysql-8.0.14-linux-glibc2.12-x86_64/data
    [root@node105 data]# 
    [root@node105 data]# ll
    total 155708
    -rw-r-----. 1 mysql mysql       56 Jan 22 06:45 auto.cnf
    -rw-------. 1 mysql mysql     1676 Jan 22 06:45 ca-key.pem
    -rw-r--r--. 1 mysql mysql     1112 Jan 22 06:45 ca.pem
    -rw-r--r--. 1 mysql mysql     1112 Jan 22 06:45 client-cert.pem
    -rw-------. 1 mysql mysql     1676 Jan 22 06:45 client-key.pem
    -rw-r-----. 1 mysql mysql     5748 Jan 22 06:45 ib_buffer_pool
    -rw-r-----. 1 mysql mysql 12582912 Jan 22 06:45 ibdata1
    -rw-r-----. 1 mysql mysql 50331648 Jan 22 06:45 ib_logfile0
    -rw-r-----. 1 mysql mysql 50331648 Jan 22 06:44 ib_logfile1
    drwxr-x---. 2 mysql mysql        6 Jan 22 06:45 #innodb_temp
    drwxr-x---. 2 mysql mysql     4096 Jan 22 06:45 mysql
    -rw-r-----. 1 mysql mysql 25165824 Jan 22 06:45 mysql.ibd
    drwxr-x---. 2 mysql mysql     4096 Jan 22 06:45 performance_schema
    -rw-------. 1 mysql mysql     1680 Jan 22 06:45 private_key.pem
    -rw-r--r--. 1 mysql mysql      452 Jan 22 06:45 public_key.pem
    -rw-r--r--. 1 mysql mysql     1112 Jan 22 06:45 server-cert.pem
    -rw-------. 1 mysql mysql     1676 Jan 22 06:45 server-key.pem
    drwxr-x---. 2 mysql mysql       27 Jan 22 06:45 sys
    -rw-r-----. 1 mysql mysql 10485760 Jan 22 06:45 undo_001
    -rw-r-----. 1 mysql mysql 10485760 Jan 22 06:45 undo_002
    [root@node105 data]# 
    上述报错的解决方案([root@node105 data]# yum -y install libaio)

    8>.启动MySQL服务

    [root@node101 ~]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/   #将MySQL加入到服务自启动
    [root@node101 ~]# 
    [root@node101 ~]# rm -rf /etc/my.cnf                            #删除它表示以mysql所有的默认参数去启动
    [root@node101 ~]# 
    [root@node101 ~]# /etc/init.d/mysql.server start                     #启动mysql服务
    Starting MySQL.Logging to '/usr/local/mysql/data/node101.yinzhengjie.org.cn.err'.
    . SUCCESS! 
    [root@node101 ~]# 
    [root@node101 ~]# ps -ef | grep mysql                            #查看mysql的启动进程
    root      41287      1  0 16:25 pts/0    00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/usr/local/mysql/data --pid-file=/usr/local/mysql/data/node101.yinzhengjie.org.cn.pid
    mysql     41372  41287  4 16:25 pts/0    00:00:01 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=node101.yinzhengjie.org.cn.err --pid-file=/usr/local/mysql/data/node101.yinzhengjie.org.cn.pid
    root      41426   2759  0 16:25 pts/0    00:00:00 grep --color=auto mysql
    [root@node101 ~]# 
    [root@node101 ~]# netstat  -untalp | grep 3306                      #查看mysql启动的端口,默认是3306
    tcp6       0      0 :::3306                 :::*                    LISTEN      41372/mysqld          
    tcp6       0      0 :::33060                :::*                    LISTEN      41372/mysqld          #这个33060是MySQL的守护进程
    [root@node101 ~]# 

    9>.连接MySQL数据库

    [root@node101 ~]# ll /usr/local/mysql/
    total 456
    drwxr-xr-x.  2 root  root    4096 Jan 15 15:46 bin
    drwxr-xr-x.  6 mysql mysql   4096 Jan 15 16:25 data
    drwxr-xr-x.  2 root  root      82 Jan 15 15:46 docs
    drwxr-xr-x.  3 root  root    4096 Jan 15 15:44 include
    drwxr-xr-x.  6 root  root    4096 Jan 15 15:46 lib
    -rw-r--r--.  1  7161 31415 335809 Oct  7 01:44 LICENSE
    -rw-r--r--.  1  7161 31415 101807 Oct  7 01:44 LICENSE.router
    drwxr-xr-x.  4 root  root      28 Jan 15 15:44 man
    -rw-r--r--.  1  7161 31415    687 Oct  7 01:44 README
    -rw-r--r--.  1  7161 31415    700 Oct  7 01:44 README.router
    drwxr-xr-x. 28 root  root    4096 Jan 15 15:46 share
    drwxr-xr-x.  2 root  root      86 Jan 15 16:03 support-files
    [root@node101 ~]# 
    [root@node101 ~]# 
    [root@node101 ~]# cat ~/.bash_profile 
    # .bash_profile
    
    # Get the aliases and functions
    if [ -f ~/.bashrc ]; then
            . ~/.bashrc
    fi
    
    # User specific environment and startup programs
    
    PATH=$PATH:$HOME/bin:/usr/local/mysql/bin
    
    export PATH
    [root@node101 ~]# 
    [root@node101 ~]# 
    [root@node101 ~]# source ~/.bash_profile 
    [root@node101 ~]# 
    [root@node101 ~]# 
    [root@node101 ~]# mysql -uroot -p
    Enter password: 
    Welcome to the MySQL monitor.  Commands end with ; or g.
    Your MySQL connection id is 8
    Server version: 8.0.13
    
    Copyright (c) 2000, 2018, 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> 
    [root@node101 ~]# mysql -uroot -p

    10>.重置MySQL的密码(mysql8.0版本和以往的MySQL5.7有所不同)

    [root@node101 ~]# mysql -uroot -p
    Enter password: 
    Welcome to the MySQL monitor.  Commands end with ; or g.
    Your MySQL connection id is 8
    Server version: 8.0.13
    
    Copyright (c) 2000, 2018, 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> alter user user() identified by 'yinzhengjie';          #重置MySQL的密码,将临时密码改为“yinzhengjie”
    Query OK, 0 rows affected (0.03 sec)
    
    mysql> exit
    Bye
    [root@node101 ~]#
    [root@node101 ~]# mysql -uroot -pyinzhengjie                #使用重置后的密码登录数据库
    mysql: [Warning] Using a password on the command line interface can be insecure.
    Welcome to the MySQL monitor.  Commands end with ; or g.
    Your MySQL connection id is 11
    Server version: 8.0.13 MySQL Community Server - GPL
    
    Copyright (c) 2000, 2018, 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> show databases;
    +--------------------+
    | Database           |
    +--------------------+
    | information_schema |
    | mysql              |
    | performance_schema |
    | sys                |
    +--------------------+
    4 rows in set (0.01 sec)
    
    mysql> quit
    Bye
    [root@node101 ~]# 

    二.迁移MySQL的安装目录

    1>.迁移服务前,需要先关闭MySQL服务

    [root@node101 ~]# /etc/init.d/mysql.server status
     SUCCESS! MySQL running (3058)
    [root@node101 ~]# 
    [root@node101 ~]# 
    [root@node101 ~]# /etc/init.d/mysql.server stop
    Shutting down MySQL... SUCCESS! 
    [root@node101 ~]# 
    [root@node101 ~]# 
    [root@node101 ~]# /etc/init.d/mysql.server status
     ERROR! MySQL is not running
    [root@node101 ~]# 

    2>.将MySQL的数据目录迁移到指定的路径

    [root@node101 ~]# mkdir -pv /yinzhengjie/data
    [root@node101 ~]# 
    [root@node101 ~]# ll /yinzhengjie/data/
    total 0
    [root@node101 ~]# 
    [root@node101 ~]# 
    [root@node101 ~]# ll /usr/local/
    total 384624
    drwxr-xr-x. 2 root root         6 Aug 12  2015 bin
    drwxr-xr-x. 2 root root         6 Aug 12  2015 etc
    drwxr-xr-x. 2 root root         6 Aug 12  2015 games
    drwxr-xr-x. 2 root root         6 Aug 12  2015 include
    drwxr-xr-x. 2 root root         6 Aug 12  2015 lib
    drwxr-xr-x. 2 root root         6 Aug 12  2015 lib64
    drwxr-xr-x. 2 root root         6 Aug 12  2015 libexec
    -rw-r--r--. 1 root root 393852364 Jan 15 05:10 mysql-8.0.13-linux-glibc2.12-x86_64
    drwxr-xr-x. 2 root root         6 Aug 12  2015 sbin
    drwxr-xr-x. 5 root root        46 Jan 15 05:59 share
    drwxr-xr-x. 2 root root         6 Aug 12  2015 src
    [root@node101 ~]# 
    [root@node101 ~]# mv /usr/local/mysql-8.0.13-linux-glibc2.12-x86_64 /yinzhengjie/data/mysql      #停止服务后,我们将MySQL的数据目录移动到我们想要修改的指定位置
    [root@node101 ~]# 
    [root@node101 ~]# ll /yinzhengjie/data/
    total 4
    drwxr-xr-x. 10 mysql mysql 4096 Jan 15 16:04 mysql
    [root@node101 ~]# 

    3>.编辑MySQL的配置文件(由于我们移动了MySQL的安装目录以及数据目录,因此默认的配置已经不生效了,需要手动指定!)

    [root@node101 ~]# 
    [root@node101 ~]# cat  /etc/my.cnf
    [mysqld]
    basedir=/yinzhengjie/data/mysql/            #指定MySQL的安装目录
    datadir=/yinzhengjie/data/mysql/data          #指定MySQL存放数据的目录
    [root@node101 ~]# 

    4>.启动MySQL服务

    [root@node101 ~]# /etc/init.d/mysql.server start
    Starting MySQL. SUCCESS! 
    [root@node101 ~]# 

    三.安装MySQL是指定安装目录

    1>.解压MySQL软件包到指定位置(指定你需要安装MySQL的路径,可以不是默认的"/usr/local"目录)

    [root@node101 local]# mkdir -pv /yinzhengjie/softwares                                #创建存放MySQL的目录位置
    mkdir: created directory ‘/yinzhengjie’
    mkdir: created directory ‘/yinzhengjie/softwares’
    [root@node101 local]# 
    [root@node101 local]# ll /yinzhengjie/softwares/
    total 0
    [root@node101 local]# 
    [root@node101 local]# tar -xf mysql-8.0.13-linux-glibc2.12-x86_64.tar.xz -C /yinzhengjie/softwares/     #创建MySQL的软件包 
    [root@node101 local]# 
    [root@node101 local]# ll /yinzhengjie/softwares/
    total 4
    drwxr-xr-x. 9 root root 4096 Jan 16 05:48 mysql-8.0.13-linux-glibc2.12-x86_64
    [root@node101 local]# 

    2>.将解压后的安装目录指定给mysql用户

    [root@node101 ~]# chown mysql:mysql -R /yinzhengjie/softwares/mysql-8.0.13-linux-glibc2.12-x86_64/
    [root@node101 ~]# 
    [root@node101 ~]# ll /yinzhengjie/softwares/
    total 4
    drwxr-xr-x. 9 mysql mysql 4096 Jan 16 05:48 mysql-8.0.13-linux-glibc2.12-x86_64
    [root@node101 ~]# 
    [root@node101 ~]# 

    3>.配置MySQL的环境变量

    [root@node101 ~]# ll /yinzhengjie/softwares/
    total 4
    drwxr-xr-x. 9 mysql mysql 4096 Jan 16 05:48 mysql-8.0.13-linux-glibc2.12-x86_64
    [root@node101 ~]# 
    [root@node101 ~]# ln -s /yinzhengjie/softwares/mysql-8.0.13-linux-glibc2.12-x86_64/ /yinzhengjie/softwares/mysql
    [root@node101 ~]# 
    [root@node101 ~]# ll /yinzhengjie/softwares/
    total 4
    lrwxrwxrwx. 1 root  root    59 Jan 16 05:57 mysql -> /yinzhengjie/softwares/mysql-8.0.13-linux-glibc2.12-x86_64/
    drwxr-xr-x. 9 mysql mysql 4096 Jan 16 05:48 mysql-8.0.13-linux-glibc2.12-x86_64
    [root@node101 ~]# 
    [root@node101 ~]# cat ~/.bash_profile 
    # .bash_profile
    
    # Get the aliases and functions
    if [ -f ~/.bashrc ]; then
            . ~/.bashrc
    fi
    
    # User specific environment and startup programs
    
    PATH=$PATH:$HOME/bin:/yinzhengjie/softwares/mysql/bin/
    
    export PATH
    [root@node101 ~]# 
    [root@node101 ~]# 
    [root@node101 ~]# source ~/.bash_profile 
    [root@node101 ~]# 

    4>.初始化MySQL数据库

    [root@node101 ~]# mysqld --initialize --user=mysql --basedir=/yinzhengjie/softwares/mysql --datadir=/yinzhengjie/softwares/mysql/data &
    [1] 4106
    [root@node101 ~]# 2019-01-16T14:00:24.941001Z 0 [System] [MY-013169] [Server] /yinzhengjie/softwares/mysql-8.0.13-linux-glibc2.12-x86_64/bin/mysqld (mysqld 8.0.13) initializing of server in progress as process 4106
    2019-01-16T14:00:33.851566Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: bSaeurfCP5)?    #注意,记住这里的临时密码!
    2019-01-16T14:00:40.575983Z 0 [System] [MY-013170] [Server] /yinzhengjie/softwares/mysql-8.0.13-linux-glibc2.12-x86_64/bin/mysqld (mysqld 8.0.13) initializing of server has completed
    
    [1]+  Done                    mysqld --initialize --user=mysql --basedir=/yinzhengjie/softwares/mysql --datadir=/yinzhengjie/softwares/mysql/data
    [root@node101 ~]# 
    [root@node101 ~]# 
    [root@node101 ~]# ll /yinzhengjie/softwares/mysql/data/
    total 155708
    -rw-r-----. 1 mysql mysql       56 Jan 16 06:00 auto.cnf
    -rw-------. 1 mysql mysql     1680 Jan 16 06:00 ca-key.pem
    -rw-r--r--. 1 mysql mysql     1112 Jan 16 06:00 ca.pem
    -rw-r--r--. 1 mysql mysql     1112 Jan 16 06:00 client-cert.pem
    -rw-------. 1 mysql mysql     1680 Jan 16 06:00 client-key.pem
    -rw-r-----. 1 mysql mysql     5753 Jan 16 06:00 ib_buffer_pool
    -rw-r-----. 1 mysql mysql 12582912 Jan 16 06:00 ibdata1
    -rw-r-----. 1 mysql mysql 50331648 Jan 16 06:00 ib_logfile0
    -rw-r-----. 1 mysql mysql 50331648 Jan 16 06:00 ib_logfile1
    drwxr-x---. 2 mysql mysql        6 Jan 16 06:00 #innodb_temp
    drwxr-x---. 2 mysql mysql     4096 Jan 16 06:00 mysql
    -rw-r-----. 1 mysql mysql 25165824 Jan 16 06:00 mysql.ibd
    drwxr-x---. 2 mysql mysql     4096 Jan 16 06:00 performance_schema
    -rw-------. 1 mysql mysql     1680 Jan 16 06:00 private_key.pem
    -rw-r--r--. 1 mysql mysql      452 Jan 16 06:00 public_key.pem
    -rw-r--r--. 1 mysql mysql     1112 Jan 16 06:00 server-cert.pem
    -rw-------. 1 mysql mysql     1676 Jan 16 06:00 server-key.pem
    drwxr-x---. 2 mysql mysql       27 Jan 16 06:00 sys
    -rw-r-----. 1 mysql mysql 10485760 Jan 16 06:00 undo_001
    -rw-r-----. 1 mysql mysql 10485760 Jan 16 06:00 undo_002
    [root@node101 ~]# 
    [root@node101 ~]# 

    5>.修改MySQL的配置文件

    [root@node101 ~]# cat /etc/my.cnf
    [mysqld]
    basedir=/yinzhengjie/softwares/mysql/
    datadir=/yinzhengjie/softwares/mysql/data/
    [root@node101 ~]# 

    6>.拷贝MySQL的启动脚本到系统自启动路径下并启动MySQL服务

    [root@node101 ~]# 
    [root@node101 ~]# cp /yinzhengjie/softwares/mysql/support-files/mysql.server /etc/init.d/
    [root@node101 ~]# 
    [root@node101 ~]# /etc/init.d/mysql.server start
    Starting MySQL.Logging to '/yinzhengjie/softwares/mysql/data/node101.yinzhengjie.org.cn.err'.
    . SUCCESS! 
    [root@node101 ~]# 
    [root@node101 ~]# 
    [root@node101 ~]# 
    [root@node101 ~]# /etc/init.d/mysql.server status
     SUCCESS! MySQL running (4397)
    [root@node101 ~]# 
    [root@node101 ~]# 
    [root@node101 ~]# ps -ef | grep mysql
    root       4285      1  0 06:04 pts/0    00:00:00 /bin/sh /yinzhengjie/softwares/mysql//bin/mysqld_safe --datadir=/yinzhengjie/softwares/mysql/data/ --pid-file=/yinzhengjie/softwares/mysql/data//node101.yinzhengjie.org.cn.pid
    mysql      4397   4285  3 06:04 pts/0    00:00:00 /yinzhengjie/softwares/mysql/bin/mysqld --basedir=/yinzhengjie/softwares/mysql/ --datadir=/yinzhengjie/softwares/mysql/data --plugin-dir=/yinzhengjie/softwares/mysql//lib/plugin --user=mysql --log-error=node101.yinzhengjie.org.cn.err --pid-file=/yinzhengjie/softwares/mysql/data//node101.yinzhengjie.org.cn.pid
    root       4466   2800  0 06:04 pts/0    00:00:00 grep --color=auto mysql
    [root@node101 ~]# 
    [root@node101 ~]# 

    7>.登录MySQL数据库

    [root@node101 ~]# mysql -uroot -pyinzhengjie          #我这里想用“yinzhengjie”作为密码登录,很显然失败了,因为我还没有授权!
    mysql: [Warning] Using a password on the command line interface can be insecure.
    ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
    [root@node101 ~]# 
    [root@node101 ~]# 
    [root@node101 ~]# mysql -uroot -p
    Enter password:   #注意,这里的密码是第4步骤初始化时的密码
    Welcome to the MySQL monitor.  Commands end with ; or g.
    Your MySQL connection id is 9
    Server version: 8.0.13
    
    Copyright (c) 2000, 2018, 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> show databases;  #注意,虽然我们使用临时密码登录成功了,但是我们不能执行任何的SQL语句,我们需要先修改密码才能执行具体的SQL。
    ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
    mysql> 
    mysql> alter user user() identified by 'yinzhengjie';    #我们这里将当前用户的密码修改为“yinzhegjie”
    Query OK, 0 rows affected (0.01 sec)
    
    mysql> quit
    Bye
    [root@node101 ~]# 
    [root@node101 ~]# mysql -uroot -pyinzhengjie      #此时,我们在用“yinzhegjie”这个字符串登录是成功的!
    mysql: [Warning] Using a password on the command line interface can be insecure.
    Welcome to the MySQL monitor.  Commands end with ; or g.
    Your MySQL connection id is 10
    Server version: 8.0.13 MySQL Community Server - GPL
    
    Copyright (c) 2000, 2018, 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> show databases;
    +--------------------+
    | Database           |
    +--------------------+
    | information_schema |
    | mysql              |
    | performance_schema |
    | sys                |
    +--------------------+
    4 rows in set (0.01 sec)
    
    mysql> quit
    Bye
    [root@node101 ~]# 

      

    四.MySQL多实例安装

    1>.将安装好的MySQL目录拷贝一份

    [root@node101 ~]# 
    [root@node101 ~]# mv /yinzhengjie/softwares/mysql-8.0.13-linux-glibc2.12-x86_64/ /yinzhengjie/softwares/mysql
    [root@node101 ~]# 
    [root@node101 ~]# ll /yinzhengjie/softwares/
    total 4
    drwxr-xr-x. 10 mysql mysql 4096 Jan 16 06:00 mysql
    [root@node101 ~]# 
    [root@node101 ~]# cp -r /yinzhengjie/softwares/mysql /yinzhengjie/softwares/mysql2
    [root@node101 ~]# 
    [root@node101 ~]# ll /yinzhengjie/softwares/
    total 8
    drwxr-xr-x. 10 mysql mysql 4096 Jan 16 06:00 mysql
    drwxr-xr-x. 10 root  root  4096 Jan 16 06:18 mysql2
    [root@node101 ~]# 
    [root@node101 ~]# chown mysql:mysql -R /yinzhengjie/softwares/mysql2
    [root@node101 ~]# 
    [root@node101 ~]# ll /yinzhengjie/softwares/
    total 8
    drwxr-xr-x. 10 mysql mysql 4096 Jan 16 06:00 mysql
    drwxr-xr-x. 10 mysql mysql 4096 Jan 16 06:18 mysql2      #该目录是我们拷贝后MySQL目录
    [root@node101 ~]# 
    [root@node101 ~]# 

    2>.检查已经启动的MySQL服务

    [root@node101 ~]# /etc/init.d/mysql.server status
     SUCCESS! MySQL running (4397)
    [root@node101 ~]# 
    [root@node101 ~]# 
    [root@node101 ~]# mysql -uroot -pyinzhengjie
    mysql: [Warning] Using a password on the command line interface can be insecure.
    Welcome to the MySQL monitor.  Commands end with ; or g.
    Your MySQL connection id is 11
    Server version: 8.0.13 MySQL Community Server - GPL
    
    Copyright (c) 2000, 2018, 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> show variables like '%sock%';
    +-----------------------------------------+------------------+
    | Variable_name                           | Value            |
    +-----------------------------------------+------------------+
    | mysqlx_socket                           | /tmp/mysqlx.sock |   ----->#这里指定的了mysqlx的socket文件
    | performance_schema_max_socket_classes   | 10               |
    | performance_schema_max_socket_instances | -1               |
    | socket                                  | /tmp/mysql.sock  |   ------>#这里指定了mysql的默认socket文件
    +-----------------------------------------+------------------+
    4 rows in set (0.10 sec)
    
    mysql> quit
    Bye
    [root@node101 ~]# 
    [root@node101 ~]# netstat -untalp | grep 3306
    tcp6       0      0 :::3306                 :::*                    LISTEN      4397/mysqld        #当前MySQL的实例     
    tcp6       0      0 :::33060                :::*                    LISTEN      4397/mysqld          #当前MySQL的守护进程
    [root@node101 ~]# 
    [root@node101 ~]# 

    3>.启动新拷贝的MySQL实例

    [root@node101 ~]# cat /etc/my3307.cnf                         #我们需要定义我们的配置文件
    [mysqld]
    basedir=/yinzhengjie/softwares/mysql2/
    datadir=/yinzhengjie/softwares/mysql2/data/
    port=3307
    socket=/tmp/mysql3307.sock
    mysqlx_port=33070
    mysqlx_socket=/tmp/mysqlx33070.sock
    [root@node101 ~]# 
    [root@node101 ~]# mysqld --defaults-file=/etc/my3307.cnf --user=mysql &    #启动咱们配置好的实例,此处我们需要指定相应的MySQL配置文件
    [1] 4945
    [root@node101 ~]# 2019-01-16T14:34:04.894011Z 0 [System] [MY-010116] [Server] /yinzhengjie/softwares/mysql/bin/mysqld (mysqld 8.0.13) starting as process 4945
    2019-01-16T14:34:05.682348Z 0 [System] [MY-010229] [Server] Starting crash recovery...
    2019-01-16T14:34:05.692916Z 0 [System] [MY-010232] [Server] Crash recovery finished.
    2019-01-16T14:34:05.761907Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
    2019-01-16T14:34:05.782447Z 0 [System] [MY-010931] [Server] /yinzhengjie/softwares/mysql/bin/mysqld: ready for connections. Version: '8.0.13'  socket: '/tmp/mysql3307.sock'  port: 3307  MySQL Community Server - GPL.
    2019-01-16T14:34:05.808012Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Socket: '/tmp/mysqlx33070.sock' bind-address: '::' port: 33070
    
    [root@node101 ~]# 
    [root@node101 ~]# 
    [root@node101 ~]# ps -ef | grep mysql
    root       4285      1  0 06:04 pts/0    00:00:00 /bin/sh /yinzhengjie/softwares/mysql//bin/mysqld_safe --datadir=/yinzhengjie/softwares/mysql/data/ --pid-file=/yinzhengjie/softwares/mysql/data//node101.yinzhengjie.org.cn.pid
    mysql      4397   4285  0 06:04 pts/0    00:00:10 /yinzhengjie/softwares/mysql/bin/mysqld --basedir=/yinzhengjie/softwares/mysql/ --datadir=/yinzhengjie/softwares/mysql/data --plugin-dir=/yinzhengjie/softwares/mysql//lib/plugin --user=mysql --log-error=node101.yinzhengjie.org.cn.err --pid-file=/yinzhengjie/softwares/mysql/data//node101.yinzhengjie.org.cn.pid
    mysql      4945   2800  1 06:34 pts/0    00:00:00 mysqld --defaults-file=/etc/my3307.cnf --user=mysql    #这里是我们刚刚启动的MySQL服务,想必大家对这个配置文件名称应该都眼熟吧!
    root       4997   2800  0 06:34 pts/0    00:00:00 grep --color=auto mysql
    [root@node101 ~]# 
    [root@node101 ~]# netstat -untalp | grep 3307      #这是我们新启动的MySQL实例端口
    tcp6       0      0 :::3307                 :::*                    LISTEN      4945/mysqld         
    tcp6       0      0 :::33070                :::*                    LISTEN      4945/mysqld         
    [root@node101 ~]# 
    [root@node101 ~]# 
    [root@node101 ~]# netstat -untalp | grep 3306      #这个是咱们之前就以及启动的端口
    tcp6       0      0 :::3306                 :::*                    LISTEN      4397/mysqld         
    tcp6       0      0 :::33060                :::*                    LISTEN      4397/mysqld         
    [root@node101 ~]# 
    [root@node101 ~]# 

    4>.连接我们启动的MySQL目录

    [root@node101 ~]# mysql -uroot -pyinzhengjie -S /tmp/mysql3307.sock        #使用“-S”选项指定本地socket文件,我们知道使用的就是"/tmp/mysql.sock"
    mysql: [Warning] Using a password on the command line interface can be insecure.
    Welcome to the MySQL monitor.  Commands end with ; or g.
    Your MySQL connection id is 8
    Server version: 8.0.13 MySQL Community Server - GPL
    
    Copyright (c) 2000, 2018, 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> show databases;
    +--------------------+
    | Database           |
    +--------------------+
    | information_schema |
    | mysql              |
    | performance_schema |
    | sys                |
    +--------------------+
    4 rows in set (0.00 sec)
    
    mysql> CREATE DATABASE yinzhengjie CHARACTER SET utf8;      #我们在3307端口的数据库实例创建一个MySQL数据库
    Query OK, 1 row affected, 1 warning (0.02 sec)
    
    mysql> show databases;
    +--------------------+
    | Database           |
    +--------------------+
    | information_schema |
    | mysql              |
    | performance_schema |
    | sys                |
    | yinzhengjie        |
    +--------------------+
    5 rows in set (0.00 sec)
    
    mysql> quit
    Bye
    [root@node101 ~]# 
    [root@node101 ~]# mysql -uroot -pyinzhengjie 
    mysql: [Warning] Using a password on the command line interface can be insecure.
    Welcome to the MySQL monitor.  Commands end with ; or g.
    Your MySQL connection id is 12
    Server version: 8.0.13 MySQL Community Server - GPL
    
    Copyright (c) 2000, 2018, 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> show databases;          #我们可以发现在3307端口的MySQL中创建的“yinzhengjie”数据库并没有影响当前的(3306端口)数据库信息!
    +--------------------+
    | Database           |
    +--------------------+
    | information_schema |
    | mysql              |
    | performance_schema |
    | sys                |
    +--------------------+
    4 rows in set (0.00 sec)
    
    mysql> quit
    Bye
    [root@node101 ~]# 

      扩展小提示:

    [root@node101 ~]# mysql -uroot -pyinzhengjie -S /tmp/mysql3307.sock
    mysql: [Warning] Using a password on the command line interface can be insecure.
    Welcome to the MySQL monitor.  Commands end with ; or g.
    Your MySQL connection id is 9
    Server version: 8.0.13 MySQL Community Server - GPL
    
    Copyright (c) 2000, 2018, 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> show variables like '%sock%';
    +-----------------------------------------+-----------------------+
    | Variable_name                           | Value                 |
    +-----------------------------------------+-----------------------+
    | mysqlx_socket                           | /tmp/mysqlx33070.sock |
    | performance_schema_max_socket_classes   | 10                    |
    | performance_schema_max_socket_instances | -1                    |
    | socket                                  | /tmp/mysql3307.sock   |
    +-----------------------------------------+-----------------------+
    4 rows in set (0.01 sec)
    
    mysql> quit
    Bye
    [root@node101 ~]# 
    [root@node101 ~]# 
    [root@node101 ~]# mysql -uroot -pyinzhengjie 
    mysql: [Warning] Using a password on the command line interface can be insecure.
    Welcome to the MySQL monitor.  Commands end with ; or g.
    Your MySQL connection id is 13
    Server version: 8.0.13 MySQL Community Server - GPL
    
    Copyright (c) 2000, 2018, 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> show variables like '%sock%';
    +-----------------------------------------+------------------+
    | Variable_name                           | Value            |
    +-----------------------------------------+------------------+
    | mysqlx_socket                           | /tmp/mysqlx.sock |
    | performance_schema_max_socket_classes   | 10               |
    | performance_schema_max_socket_instances | -1               |
    | socket                                  | /tmp/mysql.sock  |
    +-----------------------------------------+------------------+
    4 rows in set (0.01 sec)
    
    mysql> quit
    Bye
    [root@node101 ~]# 
    查看socket配置文件(mysql> show variables like '%sock%';)
    [root@node101 ~]# 
    [root@node101 ~]# ll /yinzhengjie/softwares/mysql/data/
    total 168016
    -rw-r-----. 1 mysql mysql       56 Jan 16 06:00 auto.cnf
    -rw-r-----. 1 mysql mysql      489 Jan 16 06:07 binlog.000001
    -rw-r-----. 1 mysql mysql       16 Jan 16 06:04 binlog.index
    -rw-------. 1 mysql mysql     1680 Jan 16 06:00 ca-key.pem
    -rw-r--r--. 1 mysql mysql     1112 Jan 16 06:00 ca.pem
    -rw-r--r--. 1 mysql mysql     1112 Jan 16 06:00 client-cert.pem
    -rw-------. 1 mysql mysql     1680 Jan 16 06:00 client-key.pem
    -rw-r-----. 1 mysql mysql     5753 Jan 16 06:00 ib_buffer_pool
    -rw-r-----. 1 mysql mysql 12582912 Jan 16 06:07 ibdata1
    -rw-r-----. 1 mysql mysql 50331648 Jan 16 06:07 ib_logfile0
    -rw-r-----. 1 mysql mysql 50331648 Jan 16 06:00 ib_logfile1
    -rw-r-----. 1 mysql mysql 12582912 Jan 16 06:04 ibtmp1
    drwxr-x---. 2 mysql mysql     4096 Jan 16 06:04 #innodb_temp
    drwxr-x---. 2 mysql mysql     4096 Jan 16 06:00 mysql
    -rw-r-----. 1 mysql mysql 25165824 Jan 16 06:07 mysql.ibd
    -rw-r-----. 1 mysql mysql      602 Jan 16 06:04 node101.yinzhengjie.org.cn.err
    -rw-r-----. 1 mysql mysql        5 Jan 16 06:04 node101.yinzhengjie.org.cn.pid
    drwxr-x---. 2 mysql mysql     4096 Jan 16 06:00 performance_schema
    -rw-------. 1 mysql mysql     1680 Jan 16 06:00 private_key.pem
    -rw-r--r--. 1 mysql mysql      452 Jan 16 06:00 public_key.pem
    -rw-r--r--. 1 mysql mysql     1112 Jan 16 06:00 server-cert.pem
    -rw-------. 1 mysql mysql     1676 Jan 16 06:00 server-key.pem
    drwxr-x---. 2 mysql mysql       27 Jan 16 06:00 sys
    -rw-r-----. 1 mysql mysql 10485760 Jan 16 06:07 undo_001
    -rw-r-----. 1 mysql mysql 10485760 Jan 16 06:04 undo_002
    [root@node101 ~]# 
    [root@node101 ~]# 
    [root@node101 ~]# 
    [root@node101 ~]# 
    [root@node101 ~]# 
    [root@node101 ~]# 
    [root@node101 ~]# ll /yinzhengjie/softwares/mysql2/data/
    total 168020
    -rw-r-----. 1 mysql mysql       56 Jan 16 06:19 auto.cnf
    -rw-r-----. 1 mysql mysql      489 Jan 16 06:34 binlog.000001
    -rw-r-----. 1 mysql mysql      376 Jan 16 06:41 binlog.000002
    -rw-r-----. 1 mysql mysql       32 Jan 16 06:34 binlog.index
    -rw-------. 1 mysql mysql     1680 Jan 16 06:19 ca-key.pem
    -rw-r--r--. 1 mysql mysql     1112 Jan 16 06:19 ca.pem
    -rw-r--r--. 1 mysql mysql     1112 Jan 16 06:19 client-cert.pem
    -rw-------. 1 mysql mysql     1680 Jan 16 06:19 client-key.pem
    -rw-r-----. 1 mysql mysql     5753 Jan 16 06:19 ib_buffer_pool
    -rw-r-----. 1 mysql mysql 12582912 Jan 16 06:41 ibdata1
    -rw-r-----. 1 mysql mysql 50331648 Jan 16 06:41 ib_logfile0
    -rw-r-----. 1 mysql mysql 50331648 Jan 16 06:18 ib_logfile1
    -rw-r-----. 1 mysql mysql 12582912 Jan 16 06:34 ibtmp1
    drwxr-x---. 2 mysql mysql     4096 Jan 16 06:34 #innodb_temp
    drwxr-x---. 2 mysql mysql     4096 Jan 16 06:19 mysql
    -rw-r-----. 1 mysql mysql 25165824 Jan 16 06:41 mysql.ibd
    -rw-r-----. 1 mysql mysql      602 Jan 16 06:19 node101.yinzhengjie.org.cn.err
    -rw-r-----. 1 mysql mysql        5 Jan 16 06:19 node101.yinzhengjie.org.cn.pid
    -rw-r-----. 1 mysql mysql        5 Jan 16 06:34 node101.yinzhengjie.org.pid
    drwxr-x---. 2 mysql mysql     4096 Jan 16 06:19 performance_schema
    -rw-------. 1 mysql mysql     1680 Jan 16 06:19 private_key.pem
    -rw-r--r--. 1 mysql mysql      452 Jan 16 06:19 public_key.pem
    -rw-r--r--. 1 mysql mysql     1112 Jan 16 06:19 server-cert.pem
    -rw-------. 1 mysql mysql     1676 Jan 16 06:19 server-key.pem
    drwxr-x---. 2 mysql mysql       27 Jan 16 06:19 sys
    -rw-r-----. 1 mysql mysql 10485760 Jan 16 06:34 undo_001
    -rw-r-----. 1 mysql mysql 10485760 Jan 16 06:41 undo_002
    drwxr-x---. 2 mysql mysql        6 Jan 16 06:41 yinzhengjie
    [root@node101 ~]# 
    对比2个实例底层的MySQL存储情况([root@node101 ~]# ll /yinzhengjie/softwares/mysql/data/)

      推荐阅读1:在Mac OS环境下安装mysql服务

      推荐阅读2:Windows环境安装MySQL数据库

      推荐阅读3:使用yum源的方式单机部署MySQL8.0.13

  • 相关阅读:
    并发队列ConcurrentLinkedQueue和阻塞队列LinkedBlockingQueue用法
    RabbitMQ官方文档翻译之Remote procedure call(六)
    RabbitMQ官方文档翻译之Topics(五)
    数据库调优教程(八) 什么情况下不要使用索引
    数据库调优教程(七)索引的代价
    数据库调优教程(六) 索引的相关操作
    数据库调优教程(五) 索引的作用和索引的种类
    数据库调优教程(四)Explain性能分析命令
    数据库调优教程(三)记录慢查询
    数据库调优教程(二)慢查询数据准备
  • 原文地址:https://www.cnblogs.com/yinzhengjie/p/10201038.html
Copyright © 2020-2023  润新知