• Centos 7下编译安装Mysql


    (1)官网下载地址:https://dev.mysql.com/downloads/mysql/

    此处下载的是 mysql-boost-5.7.24.tar.gz

    百度云下载地址:https://pan.baidu.com/s/1wDAJawz2hUEMbzOVte-bdQ

    提取码:gfqo

    (2)安装依赖包

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

    (3)解压源码包并配置

    cd /usr/local/src
    tar -zxf mysql-boost-5.7.24.tar.gz
    cd mysql-5.7.24/
    cmake 
    -DCMAKE_INSTALL_PREFIX=/usr/local/mysql 
    -DMYSQL_DATADIR=/usr/local/mysql/data 
    -DSYSCONFDIR=/usr/local/mysql 
    -DWITH_MYISAM_STORAGE_ENGINE=1 
    -DWITH_INNOBASE_STORAGE_ENGINE=1 
    -DWITH_MEMORY_STORAGE_ENGINE=1 
    -DWITH_READLINE=1 
    -DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock 
    -DMYSQL_TCP_PORT=3306 
    -DENABLED_LOCAL_INFILE=1 
    -DWITH_PARTITION_STORAGE_ENGINE=1 
    -DEXTRA_CHARSETS=all 
    -DDEFAULT_CHARSET=utf8 
    -DDEFAULT_COLLATION=utf8_general_ci 
    -DWITH_BOOST=boost

    以下为上述配置的说明

    cmake 
    -DCMAKE_INSTALL_PREFIX=/usr/local/mysql      安装根目录
    -DMYSQL_DATADIR=/data/3306/data                  数据存储目录
    -DSYSCONFDIR=/data/3306                                配置文件(my.cnf)目录 (貌似没用,配置文件依然在/etc/my.cnf)
    -DWITH_MYISAM_STORAGE_ENGINE=1                编译myisam存储引擎,默认的存储引擎,不加也可以
    -DWITH_INNOBASE_STORAGE_ENGINE=1              支持InnoDB存储引擎,这个也是默认安装的
    -DWITH_MEMORY_STORAGE_ENGINE=1                支持MEMORY引擎 
    -DWITH_READLINE=1                                             使用readline功能
    -DMYSQL_UNIX_ADDR=/data/3306/mysql.sock      sock存放到/data/3306目录
    -DMYSQL_TCP_PORT=3306                         数据库端口
    -DENABLED_LOCAL_INFILE=1                       可以使用load data infile命令从本地导入文件
    -DWITH_PARTITION_STORAGE_ENGINE=1       安装数据库分区
    -DEXTRA_CHARSETS=all                               支持所有字符集
    -DDEFAULT_CHARSET=utf8                     默认字符集
    -DDEFAULT_COLLATION=utf8_general_ci        设置默认效验字符集排序规则,要和DDEFAULT_CHARSET一起用
    -DWITH_BOOST=boost    从MySQL 5.7.5开始Boost库是必需的

     (4)编译及安装

    make && make install

    (5)添加用户和组

    groupadd mysql
    useradd -g mysql mysql
    chown -R mysql:mysql /usr/local/mysql

    (6)初始化

    cd /usr/local/mysql/bin
    ./mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data/

    注意:初始化完了需要记住root密码

    出现以下说明初始化成功
    2018-11-12T01:25:29.316210Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
    2018-11-12T01:25:30.314274Z 0 [Warning] InnoDB: New log files created, LSN=45790
    2018-11-12T01:25:30.441468Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
    2018-11-12T01:25:30.512508Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: d7df9433-e619-11e8-804b-00163e0851f0.
    2018-11-12T01:25:30.517175Z 0 [Warning] Gtid table is not ready to be used. Table ‘mysql.gtid_executed’ cannot be opened.
    2018-11-12T01:25:30.517899Z 1 [Note] A temporary password is generated for root@localhost: _1ahqhzYqtMd

     (7)写入环境变量

    echo "export PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile
    source /etc/profile

    (8)修改配置文件

    vim /etc/my.cnf

    配置如下:

    [mysqld]
    basedir = /usr/local/mysql
    datadir = /usr/local/mysql/data
    socket = /usr/local/mysql/mysql.sock
    user = mysql
    symbolic-links=0
    
    [mysqld_safe]
    log-error = /usr/local/mysql/log-error/mariadb.log
    pid-file = /usr/local/mysql/mariadb.pid

    (9)创建日志文件并赋予权限

    mkdir -p /usr/local/mysql/log-error/
    touch /usr/local/mysql/log-error/mariadb.log
    chown -R mysql:mysql /usr/local/mysql/log-error/mariadb.log

    (10)启动Mysql

    /usr/local/mysql/support-files/mysql.server start

    (11)设置用户密码及权限

    登录mysql:

    mysql -u root -p

    修改root用户密码:

    SET PASSWORD = PASSWORD('123456');
    ALTER USER 'root'@'localhost' PASSWORD EXPIRE NEVER;
    FLUSH PRIVILEGES;

    授权所有用户:

    grant all privileges on *.* to 'root'@'%' identified by '123456' with grant option;  
    flush privileges;

    查询数据库的用户:

    use mysql;
    SELECT DISTINCT CONCAT('User: ''',user,'''@''',host,''';') AS query FROM mysql.user;
    quit; #退出mysql命令行

    (12)设置为开机自动启动Mysql

    vim /etc/rc.d/rc.local

    添加标准启动命令:

    /usr/local/mysql/support-files/mysql.server start

    给/etc/rc.d/rc.local添加可执行权限

    chmod +x /etc/rc.d/rc.local
  • 相关阅读:
    计算机视觉的常用测试数据集和源码
    Demo:基于 Flink SQL 构建流式应用
    102万行代码,1270 个问题,Flink 新版发布了什么?
    bilibili 实时平台的架构与实践
    阿里云2020上云采购季来啦!降本增效1亿补贴!
    阿里云助力宁波市教育局“甬上云校”停课不停学
    Quick BI新版本功能解读系列之-V3.5
    百万TPS高吞吐、秒级低延迟,阿里​搜索离线平台如何实现?
    五分钟学会使用 go modules(含在家办公使用技巧)
    OAM 深入解读:OAM 为云原生应用带来哪些价值?
  • 原文地址:https://www.cnblogs.com/jxl1996/p/10134415.html
Copyright © 2020-2023  润新知