乘风原创程序

  • Linux 源码安装mysql
  • 2020/8/4 1:08:20
  • 源码安装mysql

     

    tar zxf mysql-boost-5.7.11.tar.gz

    rpm -ivh cmake-2.8.12.2-4.el6.x86_64.rpm

    yum install cmake-2.8.12.2-4.el6.x86_64.rpm -y

    cd mysql-5.7.11/

    yum install gcc-c++ ncurses-devel bison -y

     

    检测

    [root@server2mysql-5.7.11]#

     cmake -DCMAKE_INSTALL_PREFIX=/usr/local/lnmp/mysql #安装目录

    -DMYSQL_DATADIR=/usr/local/lnmp/mysql/data#数据库存放目录

    -DMYSQL_UNIX_ADDR=/usr/local/lnmp/mysql/data/mysql.sock #Unix socket文件路径-DWITH_MYISAM_STORAGE_ENGINE=1 #安装 myisam 存储引擎-DWITH_INNOBASE_STORAGE_ENGINE=1# 安装 innodb 存储引擎-DWITH_PARTITION_STORAGE_ENGINE=1 -DENABLED_LOCAL_INFILE=1

    #安装数据库分区

    -DDEFAULT_CHARSET=utf8 #使用 utf8 字符

    -DDEFAULT_COLLATION=utf8_general_ci

    -DEXTRA_CHARSETS=all -DWITH_BOOST=boost/boost_1_59_0/

     

    make && make install##这个编译过程时间需要一个小时左右

    ##make install 阶段如果出现很多红色的字体,并且界面卡住了,可以直接ctrl +C中断安装状态,重新执行make install即可

    重新编译时,需要清除旧的对象文件和缓存信息

    make clean

    rm -f CmakeCache.txt

    然后再继续camakmake && make install

     

    cd /usr/local/lnmp/mysql/bin

    [root@server2 bin]# vim ~/.bash_profile

    10 PATH=$PATH:$HOME/bin:/usr/local/lnmp/mysql/bin#这样就能自动补齐

    [root@server2 bin]# source ~/.bash_profile#刷新,立即生效

    [root@server2 bin]# cd ..

    [root@server2 mysql]# cd support-files/

    [root@server2 support-files]# rpm -e `rpm -qa | grep mysql` --nodeps

    warning: /var/log/mysqld.log saved as /var/log/mysqld.log.rpmsave

    说明:由于本机之前安装过mysql 所以源码安装的时候需要清除环境影响

    这里还不能直接yum removeyum remove会把软件的依赖性一起删除,并且会导致postfix等服务启动出现故障。

    [root@server2 support-files]# yum install mysql-libs -y

    [root@server2 support-files]# yum check

    [root@server2 support-files]# /etc/init.d/postfix restart#检测是否排除上文提及的问题

    关闭 postfix:                                             [确定]

    启动 postfix:                                             [确定]

     

    [root@server2 support-files]# rpm -qa | grep mysql

    mysql-libs-5.1.71-1.el6.x86_64

    [root@server2 support-files]# cat /etc/my.cnf

    [mysqld]

    datadir=/var/lib/mysql

    socket=/var/lib/mysql/mysql.sock

    user=mysql

    # Disabling symbolic-links is recommended to prevent assorted security risks

    symbolic-links=0

     

    [mysqld_safe]

    log-error=/var/log/mysqld.log

    pid-file=/var/run/mysqld/mysqld.pid

    [root@server2 support-files]# cp /etc/my.cnf /etc/my.cnf.bak

    [root@server2 support-files]# cp my-default.cnf /etc/my.cnf

    cp:是否覆盖"/etc/my.cnf"y

    [root@server2 support-files]# file mysql.server

    mysql.server: POSIX shell script text executable

    [root@server2 support-files]# cp mysql.server /etc/init.d/mysqld#复制启动脚本

    [root@server2 mysql]# cd /var/lib/

    [root@server2 lib]# /etc/init.d/mysqld status

     ERROR! MySQL is not running

    [root@server2 lib]# cd /usr/local/lnmp/mysql/

    [root@server2 mysql]# ls

    bin  COPYING  docs  include  lib  man  mysql-test  README  share  support-files

    [root@server2 mysql]# ll

    总用量 56

    drwxr-xr-x  2 root root  4096 3月  22 23:38 bin

    -rw-r--r--  1 root root 17987 2月   2 2016 COPYING

    drwxr-xr-x  2 root root  4096 3月  22 23:37 docs

    drwxr-xr-x  3 root root  4096 3月  22 23:37 include

    drwxr-xr-x  4 root root  4096 3月  22 23:38 lib

    drwxr-xr-x  4 root root  4096 3月  22 23:37 man

    drwxr-xr-x 10 root root  4096 3月  22 23:38 mysql-test

    -rw-r--r--  1 root root  2478 2月   2 2016 README

    drwxr-xr-x 28 root root  4096 3月  22 23:38 share

    drwxr-xr-x  2 root root  4096 3月  22 23:38 support-files

     

    [root@server2 mysql]# grep mysql /etc/passwd#查看mysql这个用户信息

    mysql:x:27:27:MySQL Server:/var/lib/mysql:/bin/bash

    [root@server2 mysql]# grep mysql /etc/shadow

    mysql:!!:17218::::::

    [root@server2 mysql]# chown mysql.mysql . -R#将当前目录下所有文件的所有人所有组都设置成mysql -R表示第归

    [root@server2 mysql]# which mysql

    /usr/local/lnmp/mysql/bin/mysql

    [root@server2 mysql]# mysql_install_db --user=mysql --basedir=/usr/local/lnmp/mysql/ --datadir=/usr/local/lnmp/mysql/data

    2017-03-23 00:24:03 [WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize

    ##mysql_install_db这个命令是不被认同的,让我们用mysqld --initialize这个命令

    2017-03-23 00:24:42 [WARNING] The bootstrap log isn't empty:

    2017-03-23 00:24:42 [WARNING] 2017-03-22T16:24:03.786590Z 0 [Warning] --bootstrap is deprecated. Please consider using --initialize instead

    2017-03-22T16:24:03.792333Z 0 [Warning] Changed limits: max_open_files: 1024 (requested 5000)

    2017-03-22T16:24:03.792343Z 0 [Warning] Changed limits: table_open_cache: 431 (requested 2000)

    [root@server2 mysql]# pwd

    /usr/local/lnmp/mysql

    [root@server2 mysql]# cd data/

    [root@server2 data]# rm -fr *

    [root@server2 data]# cd ..

    [root@server2 mysql]# mysqld --initialize --user=mysql --basedir=/usr/local/lnmp/mysql/ --datadir=/usr/local/lnmp/mysql/data

    当最后输出如下:

    2017-03-22T16:27:58.726507Z 1 [Note] A temporary password is generated for root@localhost: W_Ad1p4htKk-##加粗字体是mysql的初始登陆密码

    [root@server2 mysql]# chown root.root . -R

    [root@server2 mysql]# chown mysql data -R

    [root@server2 mysql]# cd data/

    [root@server2 data]# ls

    auto.cnf        ibdata1      ib_logfile1  performance_schema

    ib_buffer_pool  ib_logfile0  mysql        sys

    [root@server2 mysql]# /etc/init.d/mysqld start

    Starting MySQL. SUCCESS!

    [root@server2 data]# ls

    auto.cnf        ib_logfile1      mysql.sock               server2.example.com.pid

    ib_buffer_pool  ibtmp1           mysql.sock.lock          sys

    ibdata1         mysql            performance_schema

    ib_logfile0     mysqld_safe.pid  server2.example.com.err

    报错信息会记录再server2.example.com.err文件中

    [root@server2 data]# mysql -p

    Enter password:

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

    Your MySQL connection id is 3

    Server version: 5.7.11

     

    Copyright (c) 2000, 2016, 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 root@localhost identified by 'lyitx+110';##重新设置密码

    Query OK, 0 rows affected (0.00 sec)

     

    mysql> show databases;

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

    | Database           |

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

    | information_schema |

    | mysql              |

    | performance_schema |

    | sys                |

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

    4 rows in set (0.00 sec)

     

    mysql> exit

    Bye

    这样mysql就安装成功了!!!