当前位置:Gxlcms > 数据库问题 > CentOS6.9编译安装MySQL5.7.16

CentOS6.9编译安装MySQL5.7.16

时间:2021-07-01 10:21:17 帮助过:4人阅读

CentOS6.9编译安装MySQL5.7.16

部署环境:

系统CentOS6.9,mysql5.7.16,boost库

系统为2G内存

1、安装依赖包,使用yum安装cmake,6.9默认yum源自带

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

2、创建mysql的用户:

    useradd  -U -s /sbin/nologin mysql

3、创建必要的文件夹,并修改其目录用户所有者:

    mkdir -pv /usr/local/mysql/etc

    mkdir -pv /data/{boost/boost_1_59_0,mysql/{data,log}}

    chown -R mysql:mysql /usr/local/mysql/

    chown -R mysql:mysql /data/mysql/

4、将boots库拷贝到boost目录下

    cp /tmp/boost/boost_1_59_0/* /data/boost/boost_1_59_0

    chown -R mysql:mysql /data/boost/

5、编译安装mysql5.7

    cd /tmp

    tar xf mysql-5.7.16.tar.gz

    cd mysql-5.7.16

    cmake \

    -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \

    -DMYSQL_DATADIR=/data/mysql/data \

    -DSYSCONFDIR=/usr/local/mysql/etc \

    -DWITH_MYISAM_STORAGE_ENGINE=1 \

    -DWITH_INNOBASE_STORAGE_ENGINE=1 \

    -DWITH_MEMORY_STORAGE_ENGINE=1 \

    -DWITH_READLINE=1 \

    -DMYSQL_UNIX_ADDR=/data/mysql/log/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=/data/boost/boost_1_59_0


    make && make install

    时间比较长

    chown -R mysql:mysql /usr/local/mysql

6、配置文件my.cnf

    [client]

    port    = 3306

    socket  = /data/mysql/log/mysql.sock


    [mysql]

    default-character-set = utf8


    [mysqld]

    # file

    datadir =/data/mysql/data

    basedir = /usr/local/mysql

    pid-file =/data/mysql/log/mysqld.pid

    log_error = /data/mysql/log/mysql.err

    port = 3306

    socket=/data/mysql/mysql.sock

    user=mysql

    character_set_server = utf8

    character_set_server = utf8

    slow_query_log = 1

    slow_query_log_file = /data/mysql/log/slowq.log

    long_query_time = 1

    log-bin=/data/mysql/log/mysql-bin.log

    # temp

    max_tmp_tables = 64

    tmp_table_size = 512M

    slave_load_tmpdir = /data/mysql/log

    tmpdir = /data/mysql/log


    # session

    back_log = 512

    skip-name-resolve

    max_allowed_packet = 32M

    max_connections = 16000

    max_connect_errors = 10000

    wait_timeout = 28800


    table_open_cache = 216

    thread_cache_size = 128



    query_cache_type = 0

    query_cache_size = 0

    key_buffer_size = 128M

    myisam_sort_buffer_size = 16M

    read_buffer_size = 16M

    read_rnd_buffer_size = 16M

    sort_buffer_size = 16M

    join_buffer_size = 16M


    # innodb

    default_storage_engine = InnoDB

    innodb_data_home_dir = /data/mysql/data

    innodb_data_file_path = ibdata1:256M:autoextend

    innodb_log_group_home_dir = /data/mysql/log

    innodb_log_files_in_group = 4

    innodb_log_file_size = 256M

    innodb_log_buffer_size = 8M

    innodb_flush_log_at_trx_commit = 2

    innodb_flush_method = O_DIRECT

    innodb_lock_wait_timeout = 50

    #innodb_thread_concurrency = 24 16

    innodb_buffer_pool_size = 1G

    innodb_io_capacity = 1500

    innodb_use_native_aio = 1

    innodb_file_per_table = 1

    innodb_open_files = 3000


    # others

    memlock = 1

    performance_schema = 0


    # replication

    server-id = 150

    binlog_format = row

    expire_logs_days = 7

    relay_log = /data/mysql/log/relay-bin

    #replicate_ignore_db = mysql

    #slave_skip_errors = 1062

    log_slave_updates = 1

    skip-slave-start

    read_only = 0

    sync_binlog = 1


    [mysqldump]

    default-character-set = utf8


    [mysqld-5.7]

    innodb_buffer_pool_dump_pct = 40

    innodb_undo_log_truncate = 1

    innodb_undo_tablespaces = 3

    innodb_max_undo_log_size = 1G

    innodb_purge_rseg_truncate_frequency = 128

    binlog_gtid_simple_recovery=1

    log_timestamps=system

    show_compatibility_56=on

    sql_mode=‘STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION‘

7、初始化数据库

    版本在5.7.6前用的是mysql_install_db

    版本5.7.6之后使用的mysqld --initialize

    #####################官网标注#####################################

    shell> bin/mysql_install_db --user=mysql    # MySQL 5.7.5

    shell> bin/mysqld --initialize --user=mysql # MySQL 5.7.6 and up

    shell> bin/mysql_ssl_rsa_setup              # MySQL 5.7.6 and up

    #####################官网标注#####################################

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

    可能会出现内存不够的报错,自己优化下调节一下buffer大小就行了

    /usr/local/mysql/bin/mysql_ssl_rsa_setup


    没有打印日志,临时密码不能用,只好破解了,后面有方法。

8、启动数据库

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

    加上绝对路径

    basedir=/usr/local/mysql

    datadir=/data/mysql/data

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

    service mysqld start

9、配置环境变量

    vim /etc/profile

    export PATH=/usr/local/mysql/bin:$PATH

    source /etc/profile

10、查看mysql临时密码,这项我这不用了,不好使,直接破解了。

    cat /root/.mysql_secret

    mysql -uroot -p`cat /root/.mysql_secret`

    如果能进去,基本上到这就截止了,可以正常使用了。

    

**不能正常登录,使用临时密码无法等进去**

11、破解密码

    mysqld_safe --defaults-file=/usr/local/mysql/etc/my.cnf --skip-grant-tables --skip-networking&

    update mysql.user set authentication_string=password(‘123456‘) where user=‘root‘;

    11.1、查找进程号,杀掉mysql进程

        ps aux | grep mysql 

        kill -9 pid

        service mysqld start

    11.2、登录mysql

        mysql -u root -p ‘password‘

        提示修改密码:

        mysql> alter user root@localhost identified by ‘123456‘;

ok了








本文出自 “LINUX” 博客,请务必保留此出处http://wangpengtai.blog.51cto.com/3882831/1919995

CentOS6.9编译安装MySQL5.7.16

标签:mysql   centos   编译安装   

人气教程排行