zoukankan      html  css  js  c++  java
  • MySQL5.5编译方式安装

    一、准备工作

    (一)上传工具包和软件包

    [root@hadoop-slave1 software]# ls
    cmake-2.8.8.tar.gz  mysql-5.5.32.tar.gz

    将所需要的cmake和mysql包上传到服务器上去。

    (二)安装工具和依赖包

    1、安装cmake

    # 解压
    [root@hadoop-slave1 software]# tar xf cmake-2.8.8.tar.gz 
    
    # 进入与编译
    [root@hadoop-slave1 software]# cd cmake-2.8.8/

     在编译过程中可能会出现Cannot find appropriate C compiler on this system,此时请安装c编译器:

    [root@hadoop-slave1 cmake-2.8.8]# yum install gcc-c++ libstdc++-devel 

    然后再进行编译:

    [root@hadoop-slave1 cmake-2.8.8]# ./configure 

    接着:

    [root@hadoop-slave1 cmake-2.8.8]# gmake
    [root@hadoop-slave1 cmake-2.8.8]# gmake install

    2、安装MySQL依赖包

    [root@hadoop-slave1 cmake-2.8.8]# yum install ncurses-devel -y

    (三)创建用户和组

    [root@hadoop-slave1 ~]# groupadd mysql
    [root@hadoop-slave1 ~]# useradd mysql -s /sbin/nologin -M -g mysql

    二、安装MySQL

    (一)安装

    # 1、解压缩
    [root@hadoop-slave1 software]# tar xf mysql-5.5.32.tar.gz 
    
    # 2、进入目录
    cd mysql-5.5.32
    
    #3、指定安装参数 
    # 安装根目录、数据集目录、 ..

      cmake . -DCMAKE_INSTALL_PREFIX=/application/mysql-5.5.32
      -DMYSQL_DATADIR=/application/mysql-5.5.32/data
      -DMYSQL_UNIX_ADDR=/application/mysql-5.5.32/tmp/mysql.sock
      -DDEFAULT_CHARSET=utf8
      -DDEFAULT_COLLATION=utf8_general_ci
      -DEXTRA_CHARSETS=gbk,gb2312,utf8,ascii
      -DENABLED_LOCAL_INFILE=ON
      -DWITH_INNOBASE_STORAGE_ENGINE=1
      -DWITH_FEDERATED_STORAGE_ENGINE=1
      -DWITH_BLACKHOLE_STORAGE_ENGINE=1
      -DWITHOUT_EXAMPLE_STORAGE_ENGINE=1
      -DWITHOUT_PARTITION_STORAGE_ENGINE=1
      -DWITH_FAST_MUTEXES=1
      -DWITH_ZLIB=bundled
      -DENABLED_LOCAL_INFILE=1
      -DWITH_READLINE=1
      -DWITH_EMBEDDED_SERVER=1
      -DWITH_DEBUG=0

    #4、编译与安装
    [root@hadoop-slave1 mysql-5.5.32]# make && make install
    #5、软连接
    [root@hadoop-slave1 mysql-5.5.32]# ln -s /application/mysql-5.5.32 /application/mysql

    (二)启动MySQL

    1、选择配置文件

    [root@hadoop-slave1 mysql-5.5.32]# cp support-files/my-small.cnf /etc/my.cnf
    cp: overwrite ‘/etc/my.cnf’? y

    2、目录授权

    # 对数据目录赋权
    [root@hadoop-slave1 mysql-5.5.32]# chown -R mysql.mysql /application/mysql-5.5.32/data/
    # .sock文件路径,需要对该目录有写的权限
    [root@hadoop-slave1 mysql-5.5.32]#chown -R mysql:mysql tmp/
    [root@hadoop-slave1 mysql-5.5.32]# chmod -R 777 tmp/

    在配置文件my.cnf中,.sock文件是在tmp目录中,所以需要有写的权限。

    3、初始化

    # 进入到安装后软连接的mysql中的script目录中
    [root@hadoop-slave1 scripts]# pwd
    /application/mysql-5.5.32/scripts
    
    # 初始化
    [root@hadoop-slave1 scripts]# ./mysql_install_db --basedir=/application/mysql-5.5.32 --datadir=/application/mysql-5.5.32/data --user=mysql
    
    Installing MySQL system tables...
    OK
    Filling help tables...
    OK

    下面是初始化的一些详细信息,它可以帮助我们完成下面的工作:

    Installing MySQL system tables...
    OK
    Filling help tables...
    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:
    
    /application/mysql-5.5.32//bin/mysqladmin -u root password 'new-password'
    /application/mysql-5.5.32//bin/mysqladmin -u root -h hadoop-slave1 password 'new-password'
    
    Alternatively you can run:
    /application/mysql-5.5.32//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 /application/mysql-5.5.32/ ; /application/mysql-5.5.32//bin/mysqld_safe &
    
    You can test the MySQL daemon with mysql-test-run.pl
    cd /application/mysql-5.5.32//mysql-test ; perl mysql-test-run.pl
    
    Please report any problems with the /application/mysql-5.5.32//scripts/mysqlbug script!
    初始化信息

     4、启动MySQL

    # 进入到 /application/mysql-5.5.32/support-files
    [root@hadoop-slave1 support-files]# ./mysql.server start
    Starting MySQL.. SUCCESS! 

    在启动MySQL中容易出现的错误是:Starting MySQL.. ERROR! The server quit without updating PID file 。

    这个时候需要查看日志文件,位于data目录下`hostname`.err文件,你可能发现是由于.sock文件写入的没有权限所导致,此时可以这样做:

    (1)查看my.cnf文件,看看.sock文件位于的目录

    (2)修改.sock文件所在的目录所有人与写入权限

    (3)删除data目录下已经生成的文件

    (4)重启MySQL

       在初始化成功后,会有这样的提示:To start mysqld at boot time you have to copy,support-files/mysql.server to the right place for your system,所以可以将上面的mysql.server脚本拷贝到系统中对应的位置:

    # 此时可以通过/etc/init.d/mysqld start启动mysql
    [root@hadoop-slave1 mysql-5.5.32]# cp support-files/mysql.server /etc/init.d/mysqld

    查看3306端口情况:

    [root@hadoop-slave1 mysql-5.5.32]# netstat -lntup|grep 3306
    tcp        0      0 0.0.0.0:3306            0.0.0.0:*               LISTEN      44671/mysqld        

    可以看到现在启动MySQL有两种方式了:

    • 在安装目录的中通过 support-files/mysql.server start启动
    • 通过etc/init.d/mysqld start启动

    5、配置环境变量

    那么如何连接MySQL服务,进入MySQL的客户端呢?

    [root@hadoop-slave1 bin]# pwd
    /application/mysql-5.5.32/bin
    [root@hadoop-slave1 bin]# ls
    innochecksum       mysql_client_test_embedded  mysql_setpermission
    msql2mysql         mysql_config                mysqlshow
    myisamchk          mysql_convert_table_format  mysqlslap
    myisam_ftdump      mysqld                      mysqltest
    myisamlog          mysqld_multi                mysqltest_embedded
    myisampack         mysqld_safe                 mysql_tzinfo_to_sql
    my_print_defaults  mysqldump                   mysql_upgrade
    mysql              mysqldumpslow               mysql_waitpid
    mysqlaccess        mysql_embedded              mysql_zap
    mysqlaccess.conf   mysql_find_rows             perror
    mysqladmin         mysql_fix_extensions        replace
    mysqlbinlog        mysqlhotcopy                resolveip
    mysqlbug           mysqlimport                 resolve_stack_dump
    mysqlcheck         mysql_plugin
    mysql_client_test  mysql_secure_installation
    [root@hadoop-slave1 bin]# ./mysql
    Welcome to the MySQL monitor.  Commands end with ; or g.
    Your MySQL connection id is 2
    Server version: 5.5.32 Source distribution
    
    Copyright (c) 2000, 2013, 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> 

    也就是说必须进入到安装目录的bin目录下执行mysql命令才可以,这是有些麻烦的,可以配置环境变量:

    # 命令行执行下面的命令即可
    echo 'export PATH=/application/mysql-5.5.32/bin:$PATH' >> /etc/profile
    tail -1 /etc/profile
    source /etc/profile
    echo $PATH

    然后再执行mysql命令就ok了。

    [root@hadoop-slave1 mysql-5.5.32]# mysql
    Welcome to the MySQL monitor.  Commands end with ; or g.
    Your MySQL connection id is 3

    在登录过程中如果碰到如下问题:Access denied for user...这类错误可按照这样的处理方式:

    [root@hadoop-slave1 mysql-5.5.32]# pkill mysqld  # 关闭MySQL服务
    [root@hadoop-slave1 mysql-5.5.32]# lsof -i:3306  #确认是否关闭
    [root@hadoop-slave1 /]# rm -rf /application/mysql-5.5.32/data/  #删除数据文件
    [root@hadoop-slave1 scripts]# ./mysql_install_db --basedir=/application/mysql-5.5.32/
    --datadir=/application/mysql-5.5.32/data --user=mysql #重新初始化

    6、添加密码

    可以看到目前数据库是没有密码的,我们可以根据初始化的提示信息来增加密码:

    [root@hadoop-slave1 mysql-5.5.32]# /application/mysql-5.5.32//bin/mysqladmin -u root password '*****'

    三、优化数据库

    对于创建的数据库可以对不需要的库等进行剔除。

    1、删除test库

    mysql> drop database test;
    Query OK, 0 rows affected (0.04 sec)
    
    mysql> show databases;
    +--------------------+
    | Database           |
    +--------------------+
    | information_schema |
    | mysql              |
    | performance_schema |
    +--------------------+
    3 rows in set (0.00 sec)

    2、删除mysql用户表中空数据

    mysql> select user,host from mysql.user;
    +------+---------------+
    | user | host          |
    +------+---------------+
    | root | 127.0.0.1     |
    | root | ::1           |
    |      | hadoop-slave1 |
    | root | hadoop-slave1 |
    |      | localhost     |
    | root | localhost     |
    +------+---------------+
    6 rows in set (0.00 sec)

    对于上面user为空的数据进行删除。

    mysql> delete from  mysql.user where user='';  #删除空数据
    Query OK, 2 rows affected (0.02 sec)
    
    mysql> select user,host from mysql.user;
    +------+---------------+
    | user | host          |
    +------+---------------+
    | root | 127.0.0.1     |
    | root | ::1           |
    | root | hadoop-slave1 |
    | root | localhost     |
    +------+---------------+
    4 rows in set (0.00 sec)

    3、设置额外管理员

     该选项是非必须的,可以建立一个和root用户一模一样的管理员,比如创建一个system管理员。

    mysql> grant all privileges on *.*  to system@'localhost' identified by '123456' with grant option;
    Query OK, 0 rows affected (0.02 sec)
    
    mysql> select user,host from mysql.user;
    +--------+---------------+
    | user   | host          |
    +--------+---------------+
    | root   | 127.0.0.1     |
    | root   | ::1           |
    | root   | hadoop-slave1 |
    | root   | localhost     |
    | system | localhost     |
    +--------+---------------+
    5 rows in set (0.00 sec)
  • 相关阅读:
    简单数学问题
    MFC 注册表编程
    Windows多线程端口扫描
    MFC Socket双向通信
    凯撒加密
    单片机滤波
    大数素性检验
    大数加法乘法
    Unsafe Code
    委托
  • 原文地址:https://www.cnblogs.com/shenjianping/p/13430779.html
Copyright © 2011-2022 走看看