暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

使用源码方式安装mysql 5.6

lovedb 2018-01-23
309

  • 导语

    mysql安装部署官方提供多种形式,最简章直接就是rpm软件包方式,这种优点很明显简单快速,缺点就是不能充分的定制,适用于初学者入门;

    还有就是二进制方式安装,这种比rpm方式更好一些,可以适度定制,并且它基于特定操作系统平台进行编译

    最后就是我们本文重点要说的,基于源码方式的,这种最灵活,可以高度定制,比如:mysql安装在什么路径,数据存储在哪个目录,端口是什么,存储引擎支持哪些等,数据库字符集配置

    缺点就是比较繁琐,初学者不易接受,因为要了解这些自定制参数的配置及含义


    我们下面以在redhat 6.5安装mysql 5.6为例,让大家对基于源码安装有个初步的理解与认识


    • 相关内容阅读

    redhat 6.5部署mysql 5.7

    使用mysql 5.5 mysqld_multi部署mysql单机多实例

    在redhat 6.5安装部署mysql 5.5.tar.gz 2进制源码文件





    • 正文

    1,确认源码安装的编译工具cmake,gcc,make已部署完毕

    [root@mygirl ~]# more etc/redhat-release 

    Red Hat Enterprise Linux Server release 6.5 (Santiago)

    [root@mygirl ~]# rpm -qa|grep cmake

    cmake-2.6.4-5.el6.x86_64

    [root@mygirl ~]# rpm -qa|grep gcc

    gcc-objc++-4.4.7-4.el6.x86_64

    gcc-gfortran-4.4.7-4.el6.x86_64

    gcc-objc-4.4.7-4.el6.x86_64

    gcc-java-4.4.7-4.el6.x86_64

    gcc-4.4.7-4.el6.x86_64

    gcc-c++-4.4.7-4.el6.x86_64

    libgcc-4.4.7-4.el6.i686

    gcc-gnat-4.4.7-4.el6.x86_64

    libgcc-4.4.7-4.el6.x86_64

    [root@mygirl ~]# rpm -qa|grep make

    automake-1.11.1-4.el6.noarch

    cmake-2.6.4-5.el6.x86_64

    make-3.81-20.el6.x86_64


    2,创建mysql用户及组

    [root@mygirl ~]# id mysql

    uid=496(mysql) gid=502(mysql) groups=502(mysql)


    3,创建存储mysql数据文件路径并授权

    [root@mygirl ~]# mkdir -p mysql56_data

    [root@mygirl ~]# chown -Rf mysql:mysql mysql56_data


    4,上传mysql 5.6源码文件

    mysql 5.6源码文件官方地址

    https://dev.mysql.com/downloads/mysql/5.6.html#downloads

    [root@mygirl ~]# mkdir -p tmp_dir

    [root@mygirl ~]# cd tmp_dir/

    [root@mygirl tmp_dir]# rz

    rz waiting to receive.

    Starting zmodem transfer.  Press Ctrl+C to cancel.

      100%   31358 KB 15679 KB/s 00:00:02       0 Errors

    [root@mygirl tmp_dir]# ll

    total 31360

    -rwxrwxrwx. 1 root root 32110958 Dec  9 14:42 mysql-5.6.39.tar.gz


    5,解压mysql 5.6源码文件

    [root@mygirl tmp_dir]# tar xvfz mysql-5.6.39.tar.gz 

    中间略

    mysql-5.6.39/zlib/zlib.3

    mysql-5.6.39/zlib/zlib.h

    mysql-5.6.39/zlib/zutil.c

    mysql-5.6.39/zlib/zutil.h

    [root@mygirl tmp_dir]# ll

    total 31364

    drwxr-xr-x. 33 7161 31415     4096 Dec  9 15:42 mysql-5.6.39

    -rwxrwxrwx.  1 root root  32110958 Dec  9 14:42 mysql-5.6.39.tar.gz


    6,执行cmake,生成编译配置文件并安装配置mysql 5.6

    关于cmake编译工具可以支持的所有编译选项,可以参阅mysql 5.6官方手册之2.9.4 MySQL Source-Configuration Options

    [root@mygirl tmp_dir]# ll

    total 31364

    drwxr-xr-x. 33 7161 31415     4096 Dec  9 15:42 mysql-5.6.39

    -rwxrwxrwx.  1 root root  32110958 Dec  9 14:42 mysql-5.6.39.tar.gz

    [root@mygirl tmp_dir]# cd mysql-5.6.39

    [root@mygirl mysql-5.6.39]# cmake .  -DCMAKE_INSTALL_PREFIX=/mysql56 \

    > -DMYSQL_DATADIR=/mysql56_data \

    > -DMYSQL_UNIX_ADDR=/mysql56_data/mysql.sock

    中间内容略(很长且消耗时间)

    -- Performing Test HAVE_IB_GCC_ATOMIC_TEST_AND_SET - Failed

    -- Performing Test HAVE_IB_ATOMIC_PTHREAD_T_GCC

    -- Performing Test HAVE_IB_ATOMIC_PTHREAD_T_GCC - Success

    -- Looking for asprintf

    -- Looking for asprintf - found

    -- Check size of pthread_t

    -- Check size of pthread_t - done

    -- Using cmake version 2.6.4

    -- Not building NDB

    -- Performing Test HAVE_PEERCRED

    -- Performing Test HAVE_PEERCRED - Success

    -- Library mysqlclient depends on OSLIBS -lpthread;m;rt;dl

    -- Googletest was not found. gtest-based unit tests will be disabled. You can run cmake . -DENABLE_DOWNLOADS=1 to automatically download and build required components from source.

    -- If you are inside a firewall, you may need to use an https proxy: export https_proxy=http://example.com:80

    -- Library mysqlserver depends on OSLIBS -lpthread;m;rt;crypt;dl;aio

    -- Skipping deb packaging on unsupported platform .

    -- CMAKE_BUILD_TYPE: RelWithDebInfo

    -- COMPILE_DEFINITIONS: HAVE_CONFIG_H

    -- CMAKE_C_FLAGS:  -Wall -Wextra -Wformat-security -Wvla -Wwrite-strings -Wdeclaration-after-statement

    -- CMAKE_CXX_FLAGS:  -Wall -Wextra -Wformat-security -Wvla -Woverloaded-virtual -Wno-unused-parameter

    -- CMAKE_C_FLAGS_RELWITHDEBINFO: -O3 -g -fabi-version=2 -fno-omit-frame-pointer -fno-strict-aliasing -DDBUG_OFF

    -- CMAKE_CXX_FLAGS_RELWITHDEBINFO: -O3 -g -fabi-version=2 -fno-omit-frame-pointer -fno-strict-aliasing -DDBUG_OFF

    -- Configuring done

    -- Generating done

    -- Build files have been written to: tmp_dir/mysql-5.6.39

    [root@mygirl mysql-5.6.39]# 

    make最消耗时间

    [root@mygirl mysql-5.6.39]# make

    中间略

    [  2%] Building CXX object extra/yassl/taocrypt/CMakeFiles/taocrypt.dir/src/asn.cpp.o

    [  2%] Building CXX object extra/yassl/taocrypt/CMakeFiles/taocrypt.dir/src/coding.cpp.o

    [  2%] Building CXX object extra/yassl/taocrypt/CMakeFiles/taocrypt.dir/src/des.cpp.o

    [  2%] Building CXX object extra/yassl/taocrypt/CMakeFiles/taocrypt.dir/src/dh.cpp.o

    [  2%] Building CXX object extra/yassl/taocrypt/CMakeFiles/taocrypt.dir/src/dsa.cpp.o

    [  2%] Building CXX object extra/yassl/taocrypt/CMakeFiles/taocrypt.dir/src/file.cpp.o

    [  2%] Building CXX object extra/yassl/taocrypt/CMakeFiles/taocrypt.dir/src/hash.cpp.o

    [  2%] Building CXX object extra/yassl/taocrypt/CMakeFiles/taocrypt.dir/src/integer.cpp.o

    [  2%] Building CXX object extra/yassl/taocrypt/CMakeFiles/taocrypt.dir/src/md2.cpp.o

    [  2%] Building CXX object extra/yassl/taocrypt/CMakeFiles/taocrypt.dir/src/md4.cpp.o

    [  3%] Building CXX object extra/yassl/taocrypt/CMakeFiles/taocrypt.dir/src/md5.cpp.o

    [  3%] Building CXX object extra/yassl/taocrypt/CMakeFiles/taocrypt.dir/src/misc.cpp.o

    [  3%] Building CXX object extra/yassl/taocrypt/CMakeFiles/taocrypt.dir/src/random.cpp.o

    [  3%] Building CXX object extra/yassl/taocrypt/CMakeFiles/taocrypt.dir/src/ripemd.cpp.o

    [  3%] Building CXX object extra/yassl/taocrypt/CMakeFiles/taocrypt.dir/src/rsa.cpp.o

    [  3%] Building CXX object extra/yassl/taocrypt/CMakeFiles/taocrypt.dir/src/sha.cpp.o

    [  3%] Building CXX object extra/yassl/taocrypt/CMakeFiles/taocrypt.dir/src/rabbit.cpp.o

    [  3%] Building CXX object extra/yassl/taocrypt/CMakeFiles/taocrypt.dir/src/hc128.cpp.o

    中间略

    [ 98%] Building CXX object libmysqld/CMakeFiles/sql_embedded.dir/__/sql/tztime.cc.o

    [ 98%] Building CXX object libmysqld/CMakeFiles/sql_embedded.dir/__/sql/uniques.cc.o

    [ 98%] Building CXX object libmysqld/CMakeFiles/sql_embedded.dir/__/sql/unireg.cc.o

    Linking CXX static library libsql_embedded.a

    [ 98%] Built target sql_embedded

    [ 98%] Generating mysqlserver_depends.c

    Scanning dependencies of target mysqlserver

    [ 99%] Building C object libmysqld/CMakeFiles/mysqlserver.dir/mysqlserver_depends.c.o

    Linking C static library libmysqld.a

    /usr/bin/ar: creating tmp_dir/mysql-5.6.39/libmysqld/libmysqld.a

    [ 99%] Built target mysqlserver

    Scanning dependencies of target mysql_client_test_embedded

    [ 99%] Building C object libmysqld/examples/CMakeFiles/mysql_client_test_embedded.dir/__/__/tests/mysql_client_test.c.o

    Linking CXX executable mysql_client_test_embedded

    [ 99%] Built target mysql_client_test_embedded

    Scanning dependencies of target mysql_embedded

    [ 99%] Building CXX object libmysqld/examples/CMakeFiles/mysql_embedded.dir/__/__/client/completion_hash.cc.o

    [ 99%] Building CXX object libmysqld/examples/CMakeFiles/mysql_embedded.dir/__/__/client/mysql.cc.o

    [ 99%] Building CXX object libmysqld/examples/CMakeFiles/mysql_embedded.dir/__/__/client/readline.cc.o

    Linking CXX executable mysql_embedded

    [ 99%] Built target mysql_embedded

    Scanning dependencies of target mysqltest_embedded

    [ 99%] Building CXX object libmysqld/examples/CMakeFiles/mysqltest_embedded.dir/__/__/client/mysqltest.cc.o

    Linking CXX executable mysqltest_embedded

    [ 99%] 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

    [root@mygirl mysql-5.6.39]# 

    [root@mygirl mysql-5.6.39]# make install

    中间略

    -- Up-to-date: mysql56/sql-bench/innotest1

    -- Up-to-date: mysql56/sql-bench/test-select

    -- Up-to-date: /mysql56/sql-bench/graph-compare-results

    -- Up-to-date: /mysql56/sql-bench/innotest1a

    -- Up-to-date: /mysql56/sql-bench/test-transactions

    -- Up-to-date: /mysql56/sql-bench/bench-count-distinct

    [root@mygirl mysql-5.6.39]# 


    7,授权mysql安装软件目录

    [root@mygirl ~]# chown -Rf mysql:mysql /mysql56

    [root@mygirl ~]# 


    8,初始化mysql 5.6数据库

    [root@mygirl ~]# /mysql56/scripts/mysql_install_db --user=mysql --basedir=/mysql56 --datadir=/mysql56_data 

    Installing MySQL system tables...2018-01-22 22:10:52 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).

    2018-01-22 22:10:52 0 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.

    2018-01-22 22:10:52 0 [Note] /mysql56/bin/mysqld (mysqld 5.6.39) starting as process 31303 ...

    2018-01-22 22:10:52 31303 [Note] InnoDB: Using atomics to ref count buffer pool pages

    2018-01-22 22:10:52 31303 [Note] InnoDB: The InnoDB memory heap is disabled

    2018-01-22 22:10:52 31303 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins

    2018-01-22 22:10:52 31303 [Note] InnoDB: Memory barrier is not used

    2018-01-22 22:10:52 31303 [Note] InnoDB: Compressed tables use zlib 1.2.3

    2018-01-22 22:10:52 31303 [Note] InnoDB: Using Linux native AIO

    2018-01-22 22:10:52 31303 [Note] InnoDB: Using CPU crc32 instructions

    2018-01-22 22:10:52 31303 [Note] InnoDB: Initializing buffer pool, size = 128.0M

    2018-01-22 22:10:52 31303 [Note] InnoDB: Completed initialization of buffer pool

    2018-01-22 22:10:52 31303 [Note] InnoDB: The first specified data file ./ibdata1 did not exist: a new database to be created!

    2018-01-22 22:10:52 31303 [Note] InnoDB: Setting file ./ibdata1 size to 12 MB

    2018-01-22 22:10:52 31303 [Note] InnoDB: Database physically writes the file full: wait...

    2018-01-22 22:10:52 31303 [Note] InnoDB: Setting log file ./ib_logfile101 size to 48 MB

    2018-01-22 22:10:52 31303 [Note] InnoDB: Setting log file ./ib_logfile1 size to 48 MB

    2018-01-22 22:10:52 31303 [Note] InnoDB: Renaming log file ./ib_logfile101 to ./ib_logfile0

    2018-01-22 22:10:52 31303 [Warning] InnoDB: New log files created, LSN=45781

    2018-01-22 22:10:52 31303 [Note] InnoDB: Doublewrite buffer not found: creating new

    2018-01-22 22:10:52 31303 [Note] InnoDB: Doublewrite buffer created

    2018-01-22 22:10:52 31303 [Note] InnoDB: 128 rollback segment(s) are active.

    2018-01-22 22:10:52 31303 [Warning] InnoDB: Creating foreign key constraint system tables.

    2018-01-22 22:10:52 31303 [Note] InnoDB: Foreign key constraint system tables created

    2018-01-22 22:10:52 31303 [Note] InnoDB: Creating tablespace and datafile system tables.

    2018-01-22 22:10:52 31303 [Note] InnoDB: Tablespace and datafile system tables created.

    2018-01-22 22:10:52 31303 [Note] InnoDB: Waiting for purge to start

    2018-01-22 22:10:52 31303 [Note] InnoDB: 5.6.39 started; log sequence number 0

    2018-01-22 22:10:53 31303 [Note] Binlog end

    2018-01-22 22:10:53 31303 [Note] InnoDB: FTS optimize thread exiting.

    2018-01-22 22:10:53 31303 [Note] InnoDB: Starting shutdown...

    2018-01-22 22:10:54 31303 [Note] InnoDB: Shutdown completed; log sequence number 1625977

    OK

    Filling help tables...2018-01-22 22:10:54 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).

    2018-01-22 22:10:54 0 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.

    2018-01-22 22:10:54 0 [Note] /mysql56/bin/mysqld (mysqld 5.6.39) starting as process 31325 ...

    2018-01-22 22:10:54 31325 [Note] InnoDB: Using atomics to ref count buffer pool pages

    2018-01-22 22:10:54 31325 [Note] InnoDB: The InnoDB memory heap is disabled

    2018-01-22 22:10:54 31325 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins

    2018-01-22 22:10:54 31325 [Note] InnoDB: Memory barrier is not used

    2018-01-22 22:10:54 31325 [Note] InnoDB: Compressed tables use zlib 1.2.3

    2018-01-22 22:10:54 31325 [Note] InnoDB: Using Linux native AIO

    2018-01-22 22:10:54 31325 [Note] InnoDB: Using CPU crc32 instructions

    2018-01-22 22:10:54 31325 [Note] InnoDB: Initializing buffer pool, size = 128.0M

    2018-01-22 22:10:54 31325 [Note] InnoDB: Completed initialization of buffer pool

    2018-01-22 22:10:54 31325 [Note] InnoDB: Highest supported file format is Barracuda.

    2018-01-22 22:10:54 31325 [Note] InnoDB: 128 rollback segment(s) are active.

    2018-01-22 22:10:54 31325 [Note] InnoDB: Waiting for purge to start

    2018-01-22 22:10:54 31325 [Note] InnoDB: 5.6.39 started; log sequence number 1625977

    2018-01-22 22:10:54 31325 [Note] Binlog end

    2018-01-22 22:10:54 31325 [Note] InnoDB: FTS optimize thread exiting.

    2018-01-22 22:10:54 31325 [Note] InnoDB: Starting shutdown...

    2018-01-22 22:10:56 31325 [Note] InnoDB: Shutdown completed; log sequence number 1625987

    OK

    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:

      /mysql56/bin/mysqladmin -u root password 'new-password'

      /mysql56/bin/mysqladmin -u root -h mygirl password 'new-password'

    Alternatively you can run:

      /mysql56/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 . ; /mysql56/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 /mysql56/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 /mysql56/my-new.cnf,

    please compare it with your file and take the changes you need.

    [root@mygirl ~]# 


    9,确认mysql 5.6初始化成功

    [root@mygirl ~]# ll /mysql56_data

    total 110604

    -rw-rw----. 1 mysql mysql 12582912 Jan 22 22:10 ibdata1

    -rw-rw----. 1 mysql mysql 50331648 Jan 22 22:10 ib_logfile0

    -rw-rw----. 1 mysql mysql 50331648 Jan 22 22:10 ib_logfile1

    drwx------. 2 mysql mysql     4096 Jan 22 22:10 mysql

    drwx------. 2 mysql mysql     4096 Jan 22 22:10 performance_schema

    drwx------. 2 mysql mysql     4096 Jan 22 22:10 test


    10,后台启动mysql 5.6

    [root@mygirl ~]# /mysql56/bin/mysqld_safe &

    [1] 31368

    [root@mygirl ~]# Logging to '/mysql56_data/mygirl.err'.

    180122 22:12:43 mysqld_safe Starting mysqld daemon with databases from /mysql56_data

    [root@mygirl ~]# ps -ef|grep mysql

    root     31368 11424  0 22:12 pts/0    00:00:00 /bin/sh /mysql56/bin/mysqld_safe

    mysql    31437 31368  4 22:12 pts/0    00:00:00 /mysql56/bin/mysqld --basedir=/mysql56 --datadir=/mysql56_data --plugin-dir=/mysql56/lib/plugin --user=mysql --log-error=mygirl.err --pid-file=mygirl.pid

    root     31460 11424  0 22:12 pts/0    00:00:00 grep mysql

    [root@mygirl ~]# 


    11,配置mysql数据库root用户密码

    [root@mygirl ~]# /mysql56/bin/mysql -u root -p

    Enter password: 

    Welcome to the MySQL monitor.  Commands end with ; or \g.

    Your MySQL connection id is 1

    Server version: 5.6.39 Source distribution

    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> 

    mysql> select host,user,password from mysql.user;

    +-----------+------+----------+

    | host      | user | password |

    +-----------+------+----------+

    | localhost | root |          |

    | mygirl    | root |          |

    | 127.0.0.1 | root |          |

    | ::1       | root |          |

    | localhost |      |          |

    | mygirl    |      |          |

    +-----------+------+----------+

    6 rows in set (0.00 sec)

    [root@mygirl ~]# /mysql56/bin/mysqladmin -u root password 'zxy'

    Warning: Using a password on the command line interface can be insecure.

    [root@mygirl ~]# /mysql56/bin/mysqladmin -u root -h mygirl password 'zxy'

    Warning: Using a password on the command line interface can be insecure.

    [root@mygirl ~]# /mysql56/bin/mysql -u root -p

    Enter password: 

    Welcome to the MySQL monitor.  Commands end with ; or \g.

    Your MySQL connection id is 6

    Server version: 5.6.39 Source distribution

    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> 

    mysql> select host,user,password from mysql.user;

    +-----------+------+-------------------------------------------+

    | host      | user | password                                  |

    +-----------+------+-------------------------------------------+

    | localhost | root | *0BE179E54992731AB04DABE559259A9F42801194 |

    | mygirl    | root | *0BE179E54992731AB04DABE559259A9F42801194 |

    | 127.0.0.1 | root |                                           |

    | ::1       | root |                                           |

    | localhost |      |                                           |

    | mygirl    |      |                                           |

    +-----------+------+-------------------------------------------+

    6 rows in set (0.00 sec)


    • 错误汇总

    1,cmake的配置选项或参数必须是大写形式,否则会报错

    cmake .  -DCMAKE_INSTALL_PREFIX=/mysql56 \

    -DMYSQL_DATADIR=/mysql56_data \

    -DMYSQL_UNIX_ADDR=/mysql56_data/mysql.sock


    2,如果需要重复运行cmake命令,须执行如下命令

    [root@mygirl mysql-5.6.39]# rm CMakeCache.txt

    rm: remove regular file `CMakeCache.txt'? y

    [root@mygirl mysql-5.6.39]# 


    3,以如下方式初始化mysql 5.6数据库会报错

    [root@mygirl ~]# /mysql56/scripts/mysql_install_db --user=mysql

    FATAL ERROR: Could not find ./bin/my_print_defaults

    If you compiled from source, you need to run 'make install' to

    copy the software into the correct location ready for operation.

    If you are using a binary release, you must either be at the top

    level of the extracted archive, or pass the --basedir option

    pointing to that location.


    文章转载自lovedb,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

    评论