美文网首页
centos7源码编译安装mysql5.7

centos7源码编译安装mysql5.7

作者: 最底层的技术渣 | 来源:发表于2020-02-20 18:28 被阅读0次

    安装环境:

    docker -> centos7.2.1511

    1、进入下载目录

    cd /usr/local/src
    

    2、下载mysql5.7 编译安装需要boost 库

    wget https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-boost-5.7.25.tar.gz
    

    获取以前老的版本下载地址:
    http://downloads.mysql.com/archives/community/

    3、解压

    tar -zxvf mysql-boost-5.7.25.tar.gz
    

    4、安装依赖包

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

    5、添加用户

    cd /usr/local/src/mysql-5.7.25
    useradd -s /sbin/nologin mysql
    

    6、编译并指定安装目录

    cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_BOOST=boost
    

    7、安装

    make && make install
    

    ---------------------------------------------配置-----------------------------------------------------

    8、编辑 /etc/my.cnf( 如果没有则创建)

    vim /etc/my.cnf
    
    [client]
    port        = 3306
    socket      = /tmp/mysql.sock
    
    [mysqld]
    port        = 3306
    socket      = /tmp/mysql.sock
    user = mysql
    
    
    basedir = /usr/local/mysql
    datadir = /data/mysql/data
    pid-file = /data/mysql/mysql.pid
    
    log_error = /data/mysql/mysql-error.log
    slow_query_log = 1
    long_query_time = 1
    slow_query_log_file = /data/mysql/mysql-slow.log
    
    
    skip-external-locking
    key_buffer_size = 32M
    max_allowed_packet = 1024M
    table_open_cache = 128
    sort_buffer_size = 768K
    net_buffer_length = 8K
    read_buffer_size = 768K
    read_rnd_buffer_size = 512K
    myisam_sort_buffer_size = 8M
    thread_cache_size = 16
    query_cache_size = 16M
    tmp_table_size = 32M
    performance_schema_max_table_instances = 1000
    
    explicit_defaults_for_timestamp = true
    #skip-networking
    max_connections = 500
    max_connect_errors = 100
    open_files_limit = 65535
    
    log_bin=mysql-bin
    binlog_format=mixed
    server_id   = 232
    expire_logs_days = 10
    early-plugin-load = ""
    
    default_storage_engine = InnoDB
    innodb_file_per_table = 1
    innodb_buffer_pool_size = 128M
    innodb_log_file_size = 32M
    innodb_log_buffer_size = 8M
    innodb_flush_log_at_trx_commit = 1
    innodb_lock_wait_timeout = 50
    
    [mysqldump]
    quick
    max_allowed_packet = 16M
    
    [mysql]
    no-auto-rehash
    
    [myisamchk]
    key_buffer_size = 32M
    sort_buffer_size = 768K
    read_buffer = 2M
    write_buffer = 2M
    

    9、创建 MySQL 相关目录及权限

    chown -R mysql:mysql /usr/local/mysql
    mkdir -p /data/mysql/{data,log,tmp}
    chown -R mysql:mysql /data/mysql
    

    10、添加 MySQL 环境变量

    vim /etc/profile
    

    ~/.bashrc文件下添加如下语句

    export MYSQL_HOME=/usr/local/mysql
    export PATH=${MYSQL_HOME}/bin:$PATH
    

    保存后,使环境变量生效

    source /etc/profile
    

    11、初始化mysql(当前路径是 /usr/local/mysql

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

    –initialize-insecure 使用空密码。你应该在生产中及时修改密码。
    或者使用 --initialize 这样的话,会为 root 用户生成一个随机的密码。

    12、拷贝可执行配置文件

    cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
    

    13、设置开机自启动并启动

    systemctl enable mysqld
    service mysqld start
    

    14、登陆MySQL(无密码)

    ./bin/mysql -hlocalhost -uroot -p
    

    备注:

    1、centosdocker容器中不存在service这个命令,会报错bash: service: command not found所以要进行安装

    yum install initscripts -y
    

    2、本地链接mysql时:Host 'gateway' is not allowed to connect to this MySQL server;

    mysql> use mysql;
    Database changed
    mysql> select 'host' from user where user='root' ;
    +------+| host |
    +------+| host |
    +------+
    1 row in set (0.00 sec) 
    mysql> update user set host = '%' where user ='root';
    Query OK, 1 row affected (0.00 sec)Rows matched: 1  Changed: 1  Warnings: 0 
    mysql> flush privileges;
    Query OK, 0 rows affected (0.01 sec) 
    mysql> select 'host'   from user where user='root';
    +------+| host |
    +------+| host |
    +------+
    1 row in set (0.00 sec)
    

    3、报错ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)


    原因一:是因为不存在/tmp/mysql.sock这个文件,但是在/tmp/目录下没有找到此文件

    find / -name mysql.sock
    ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock
    

    原因二:权限问题

    chown -R mysql:mysql /data/mysql
    

    相关文章

      网友评论

          本文标题:centos7源码编译安装mysql5.7

          本文链接:https://www.haomeiwen.com/subject/lmpnfhtx.html