Lnmp环境搭建之mysql-5.6.16的安装配置

==------------------------------------------------------------------------------------------------------------------------

注:本文仅供参考,实际操作中,具体问题,请具体分析对待!

-----== linux mysql-5.6.16   可参考:https://blog.51cto.com/13505030/2058632           【SUCCESS!】

1、获取资源
    cd /fitness/software/mysql-5.6.16/
    wget http://dev.mysql.com/downloads/mysql/mysql-5.6.16.tar.gz # 下载不了,自己后来重下载了资源

2、添加mysql用户,创建mysql目录及数据目录
    groupadd mysql
    mkdir -pv /fitness/serve/mysql
    useradd -r -g mysql -d /fitness/serve/mysql -s /sbin/nologin mysql
    chown -R mysql.mysql /fitness/serve/mysql

3、安装cmake依赖
    yum install cmake gcc* ncurses-devel -y
    Installed:
      cmake.x86_64 0:2.8.12.2-2.el7                              gcc-aarch64-linux-gnu.x86_64 0:4.8.5-16.el7.1          gcc-alpha-linux-gnu.x86_64 0:4.8.5-16.el7.1             gcc-arm-linux-gnu.x86_64 0:4.8.5-16.el7.1
      gcc-avr32-linux-gnu.x86_64 0:4.8.5-16.el7.1                gcc-bfin-linux-gnu.x86_64 0:4.8.5-16.el7.1             gcc-c++-aarch64-linux-gnu.x86_64 0:4.8.5-16.el7.1       gcc-c++-alpha-linux-gnu.x86_64 0:4.8.5-16.el7.1
      gcc-c++-arm-linux-gnu.x86_64 0:4.8.5-16.el7.1              gcc-c++-avr32-linux-gnu.x86_64 0:4.8.5-16.el7.1        gcc-c++-bfin-linux-gnu.x86_64 0:4.8.5-16.el7.1          gcc-c++-c6x-linux-gnu.x86_64 0:4.8.5-16.el7.1
      gcc-c++-cris-linux-gnu.x86_64 0:4.8.5-16.el7.1             gcc-c++-frv-linux-gnu.x86_64 0:4.8.5-16.el7.1          gcc-c++-h8300-linux-gnu.x86_64 0:4.8.5-16.el7.1         gcc-c++-hppa-linux-gnu.x86_64 0:4.8.5-16.el7.1
      gcc-c++-hppa64-linux-gnu.x86_64 0:4.8.5-16.el7.1           gcc-c++-ia64-linux-gnu.x86_64 0:4.8.5-16.el7.1         gcc-c++-m32r-linux-gnu.x86_64 0:4.8.5-16.el7.1          gcc-c++-m68k-linux-gnu.x86_64 0:4.8.5-16.el7.1
      gcc-c++-microblaze-linux-gnu.x86_64 0:4.8.5-16.el7.1       gcc-c++-mips64-linux-gnu.x86_64 0:4.8.5-16.el7.1       gcc-c++-mn10300-linux-gnu.x86_64 0:4.8.5-16.el7.1       gcc-c++-powerpc64-linux-gnu.x86_64 0:4.8.5-16.el7.1
      gcc-c++-ppc64-linux-gnu.x86_64 0:4.8.5-16.el7.1            gcc-c++-s390x-linux-gnu.x86_64 0:4.8.5-16.el7.1        gcc-c++-sh-linux-gnu.x86_64 0:4.8.5-16.el7.1            gcc-c++-sh64-linux-gnu.x86_64 0:4.8.5-16.el7.1
      gcc-c++-sparc64-linux-gnu.x86_64 0:4.8.5-16.el7.1          gcc-c++-tile-linux-gnu.x86_64 0:4.8.5-16.el7.1         gcc-c++-x86_64-linux-gnu.x86_64 0:4.8.5-16.el7.1        gcc-c++-xtensa-linux-gnu.x86_64 0:4.8.5-16.el7.1
      gcc-c6x-linux-gnu.x86_64 0:4.8.5-16.el7.1                  gcc-cris-linux-gnu.x86_64 0:4.8.5-16.el7.1             gcc-frv-linux-gnu.x86_64 0:4.8.5-16.el7.1               gcc-gfortran.x86_64 0:4.8.5-36.el7_6.2
      gcc-gnat.x86_64 0:4.8.5-36.el7_6.2                         gcc-go.x86_64 0:4.8.5-36.el7_6.2                       gcc-h8300-linux-gnu.x86_64 0:4.8.5-16.el7.1             gcc-hppa-linux-gnu.x86_64 0:4.8.5-16.el7.1
      gcc-hppa64-linux-gnu.x86_64 0:4.8.5-16.el7.1               gcc-ia64-linux-gnu.x86_64 0:4.8.5-16.el7.1             gcc-m32r-linux-gnu.x86_64 0:4.8.5-16.el7.1              gcc-m68k-linux-gnu.x86_64 0:4.8.5-16.el7.1
      gcc-microblaze-linux-gnu.x86_64 0:4.8.5-16.el7.1           gcc-mips64-linux-gnu.x86_64 0:4.8.5-16.el7.1           gcc-mn10300-linux-gnu.x86_64 0:4.8.5-16.el7.1           gcc-objc.x86_64 0:4.8.5-36.el7_6.2
      gcc-objc++.x86_64 0:4.8.5-36.el7_6.2                       gcc-plugin-devel.x86_64 0:4.8.5-36.el7_6.2             gcc-powerpc64-linux-gnu.x86_64 0:4.8.5-16.el7.1         gcc-ppc64-linux-gnu.x86_64 0:4.8.5-16.el7.1
      gcc-s390x-linux-gnu.x86_64 0:4.8.5-16.el7.1                gcc-sh-linux-gnu.x86_64 0:4.8.5-16.el7.1               gcc-sh64-linux-gnu.x86_64 0:4.8.5-16.el7.1              gcc-sparc64-linux-gnu.x86_64 0:4.8.5-16.el7.1
      gcc-tile-linux-gnu.x86_64 0:4.8.5-16.el7.1                 gcc-x86_64-linux-gnu.x86_64 0:4.8.5-16.el7.1           gcc-xtensa-linux-gnu.x86_64 0:4.8.5-16.el7.1            gccxml.x86_64 0:0.9.0-0.27.20150423.git3afa8ba.el7
      ncurses-devel.x86_64 0:5.9-14.20130511.el7_4

    Dependency Installed:
      binutils-aarch64-linux-gnu.x86_64 0:2.27-9.el7.1        binutils-alpha-linux-gnu.x86_64 0:2.27-9.el7.1            binutils-arm-linux-gnu.x86_64 0:2.27-9.el7.1               binutils-avr32-linux-gnu.x86_64 0:2.27-9.el7.1
      binutils-bfin-linux-gnu.x86_64 0:2.27-9.el7.1           binutils-c6x-linux-gnu.x86_64 0:2.27-9.el7.1              binutils-cris-linux-gnu.x86_64 0:2.27-9.el7.1              binutils-frv-linux-gnu.x86_64 0:2.27-9.el7.1
      binutils-h8300-linux-gnu.x86_64 0:2.27-9.el7.1          binutils-hppa-linux-gnu.x86_64 0:2.27-9.el7.1             binutils-hppa64-linux-gnu.x86_64 0:2.27-9.el7.1            binutils-ia64-linux-gnu.x86_64 0:2.27-9.el7.1
      binutils-m32r-linux-gnu.x86_64 0:2.27-9.el7.1           binutils-m68k-linux-gnu.x86_64 0:2.27-9.el7.1             binutils-microblaze-linux-gnu.x86_64 0:2.27-9.el7.1        binutils-mips64-linux-gnu.x86_64 0:2.27-9.el7.1
      binutils-mn10300-linux-gnu.x86_64 0:2.27-9.el7.1        binutils-powerpc64-linux-gnu.x86_64 0:2.27-9.el7.1        binutils-s390x-linux-gnu.x86_64 0:2.27-9.el7.1             binutils-sh-linux-gnu.x86_64 0:2.27-9.el7.1
      binutils-sh64-linux-gnu.x86_64 0:2.27-9.el7.1           binutils-sparc64-linux-gnu.x86_64 0:2.27-9.el7.1          binutils-tile-linux-gnu.x86_64 0:2.27-9.el7.1              binutils-x86_64-linux-gnu.x86_64 0:2.27-9.el7.1
      binutils-xtensa-linux-gnu.x86_64 0:2.27-9.el7.1         cross-binutils-common.noarch 0:2.27-9.el7.1               cross-gcc-common.noarch 0:4.8.5-16.el7.1                   gmp-devel.x86_64 1:6.0.0-15.el7
      libarchive.x86_64 0:3.1.2-10.el7_2                      libgfortran.x86_64 0:4.8.5-36.el7_6.2                     libgnat.x86_64 0:4.8.5-36.el7_6.2                          libgnat-devel.x86_64 0:4.8.5-36.el7_6.2
      libgo.x86_64 0:4.8.5-36.el7_6.2                         libgo-devel.x86_64 0:4.8.5-36.el7_6.2                     libmpc-devel.x86_64 0:1.0.1-3.el7                          libobjc.x86_64 0:4.8.5-36.el7_6.2
      libquadmath.x86_64 0:4.8.5-36.el7_6.2                   libquadmath-devel.x86_64 0:4.8.5-36.el7_6.2               mpfr-devel.x86_64 0:3.1.1-4.el7

    Complete!

4、编译安装mysql

    cmake -DCMAKE_INSTALL_PREFIX=/fitness/serve/mysql -DDEFAULT_CHARSET=utf8 -DENABLED_LOCAL_INFILE=1 -DMYSQL_DATADIR=/fitness/serve/mysql/data -DWITH_EXTRA_CHARSETS=all -DWITH_READLINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DMYSQL_TCP_PORT=3306 -DDEFAULT_COLLATION=utf8mb4_general_ci

    make
    这个过程有点长,可能得等一会

    [100%] Building CXX object libmysqld/examples/CMakeFiles/mysql_embedded.dir/__/__/client/readline.cc.o
    Linking CXX executable mysql_embedded
    [100%] Built target mysql_embedded
    Scanning dependencies of target mysqltest_embedded
    [100%] Building CXX object libmysqld/examples/CMakeFiles/mysqltest_embedded.dir/__/__/client/mysqltest.cc.o
    Linking CXX executable mysqltest_embedded
    [100%] Built target mysqltest_embedded
    Scanning dependencies of target my_safe_process
    [100%] Building CXX object mysql-test/lib/My/SafeProcess/CMakeFiles/my_safe_process.dir/safe_process.cc.o
    Linking CXX executable my_safe_process
    [100%] Built target my_safe_process

    make install

    -- Installing: /fitness/serve/mysql/man/man8/mysqld.8
    -- Installing: /fitness/serve/mysql/support-files/solaris/postinstall-solaris


5、拷贝mysql的配置文件
    cd /fitness/serve/mysql/support-files/
    cp my-default.cnf /etc/my.cnf
    cp mysql.server /etc/init.d/mysqld

    vim /etc/init.d/mysqld

    大概在46/47行,配置如下:
     46 basedir=/fitness/serve/mysql
     47 datadir=/fitness/serve/mysql/data

6、初始化数据库
    cd /fitness/serve/mysql/scripts/
    ./mysql_install_db --user=mysql --basedir=/fitness/serve/mysql/ --datadir=/fitness/serve/mysql/data

    有点报错:
    [root@iZ8vb2uz59jd5pisp87ljiZ scripts]# ./mysql_install_db --user=mysql --basedir=/fitness/serve/mysql/ --datadir=/fitness/serve/mysql/data
    Installing MySQL system tables...2019-06-25 15:19:38 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
    2019-06-25 15:19:38 14175 [ERROR] COLLATION 'utf8mb4_general_ci' is not valid for CHARACTER SET 'utf8'
    2019-06-25 15:19:38 14175 [ERROR] Aborting

    解决:
    在 vi /etc/my.cnf 文件中加上
    explicit_defaults_for_timestamp=true
    保存后再次启动就可以了。

    再次初始化
    ./mysql_install_db --user=mysql --basedir=/fitness/serve/mysql/ --datadir=/fitness/serve/mysql/data

    报错:
    [root@iZ8vb2uz59jd5pisp87ljiZ scripts]# ./mysql_install_db --user=mysql --basedir=/fitness/serve/mysql/ --datadir=/fitness/serve/mysql/data
    Installing MySQL system tables...2019-06-25 15:26:31 14525 [ERROR] COLLATION 'utf8mb4_general_ci' is not valid for CHARACTER SET 'utf8'
    2019-06-25 15:26:31 14525 [ERROR] Aborting

    2019-06-25 15:26:31 14525 [Note] Binlog end
    2019-06-25 15:26:31 14525 [Note] /fitness/serve/mysql//bin/mysqld: Shutdown complete

    处理方法:
    修改mysql配置文件my.cnf
    my.cnf一般在etc/mysql/my.cnf位置。找到后请在以下三部分里添加如下内容:
    [client]
    default-character-set = utf8mb4
    [mysql]
    default-character-set = utf8mb4
    [mysqld]
    character-set-client-handshake = FALSE
    character-set-server = utf8mb4
    collation-server = utf8mb4_unicode_ci
    init_connect=’SET NAMES utf8mb4’

    重新初始化,貌似可以了!

    To start mysqld at boot time you have to copy
    support-files/mysql.server to the right place for your system

    PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
    To do so, start the server, then issue the following commands:

      /fitness/serve/mysql//bin/mysqladmin -u root password 'new-password'
      /fitness/serve/mysql//bin/mysqladmin -u root -h iZ8vb2uz59jd5pisp87ljiZ password 'new-password'

    Alternatively you can run:

      /fitness/serve/mysql//bin/mysql_secure_installation

    which will also give you the option of removing the test
    databases and anonymous user created by default.  This is
    strongly recommended for production servers.

    See the manual for more instructions.

    You can start the MySQL daemon with:

      cd . ; /fitness/serve/mysql//bin/mysqld_safe &

    You can test the MySQL daemon with mysql-test-run.pl

      cd mysql-test ; perl mysql-test-run.pl

    Please report any problems at http://bugs.mysql.com/

    The latest information about MySQL is available on the web at

      http://www.mysql.com

    Support MySQL by buying support/licenses at http://shop.mysql.com

    WARNING: Found existing config file /fitness/serve/mysql//my.cnf on the system.
    Because this file might be in use, it was not replaced,
    but was used in bootstrap (unless you used --defaults-file)
    and when you later start the server.
    The new default config file was created as /fitness/serve/mysql//my-new.cnf,
    please compare it with your file and take the changes you need.

    WARNING: Default config file /etc/my.cnf exists on the system
    This file will be read by default by the MySQL server
    If you do not want to use this, either remove it, or use the
    --defaults-file argument to mysqld_safe when starting the server

    但,我发现提示中,有的显示了//,这里后续处理

    /fitness/serve/mysql//bin/mysqladmin -u root password 'new-password'
    /fitness/serve/mysql//bin/mysqladmin -u root -h iZ8vb2uz59jd5pisp87ljiZ password 'new-password'

    /fitness/serve/mysql//bin/mysql_secure_installation
    cd . ; /fitness/serve/mysql//bin/mysqld_safe &

    WARNING: Found existing config file /fitness/serve/mysql//my.cnf on the system.


7、把mysql加入系统服务项,并设置开机启动

    chkconfig --add mysqld

    chkconfig mysqld on


8、启动mysql

    /etc/init.d/mysqld start

    [root@iZ8vb2uz59jd5pisp87ljiZ /]# /etc/init.d/mysqld start
    Starting MySQL.                                            [  OK  ]

9、登入mysql
     /fitness/serve/mysql/bin/mysql

     [root@iZ8vb2uz59jd5pisp87ljiZ /]# /fitness/serve/mysql/bin/mysql
     Welcome to the MySQL monitor.  Commands end with ; or \g.
     Your MySQL connection id is 1
     Server version: 5.6.16 Source distribution

     Copyright (c) 2000, 2014, 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>

     mysql> show databases;
     +--------------------+
     | Database           |
     +--------------------+
     | information_schema |
     | mysql              |
     | performance_schema |
     | test               |
     +--------------------+
     4 rows in set (0.00 sec)

     mysql> select version();
     +-----------+
     | version() |
     +-----------+
     | 5.6.16    |
     +-----------+
     1 row in set (0.00 sec)


10、设置远程登录
    mysql> use mysql
    Reading table information for completion of table and column names
    You can turn off this feature to get a quicker startup with -A

    Database changed

    开启远程登录
    GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;


11、测试连接mysql数据库,成功!!!


12、mysql启动脚本加入PATH路径
    vi /etc/profile
    export PATH=/fitness/serve/mysql/bin:/fitness/serve/mysql/lib:$PATH

    source /etc/profile        #使用环境变量生效

13、启动mysql服务并加入开机自启动

    service mysqld start
    chkconfig --level 35 mysqld on

    [root@iZ8vb2uz59jd5pisp87ljiZ lib]# service mysqld start
    Starting MySQL                                             [  OK  ]

    若想修改mysql的某个用户的密码,可如下操作:
    mysqladmin -u root password '123456'


----------------------------------------------------------------------------------------------------------------------==
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值