myql 5.6 安装

Posted 刘振川的博客

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了myql 5.6 安装相关的知识,希望对你有一定的参考价值。

 

环境: centos 6.5  192.168.9.28  4核4G 虚拟机

 

一. 安装编译源码所需要的工具和库

[[email protected] ~]# yum -y install gcc gcc-c++ make ncurses-devel perl

[[email protected] soft]# ls
cmake-2.8.6.tar.gz  mysql-5.6.35.tar.gz

[[email protected] soft]# tar xf cmake-2.8.6.tar.gz -C /usr/src

[[email protected] soft]# cd /usr/src/cmake-2.8.6/
[[email protected] cmake-2.8.6]# ls
bootstrap                   cmake_uninstall.cmake.in  Docs
ChangeLog.manual            CompileFlags.cmake        doxygen.config
ChangeLog.txt               configure                 Example
cmake.1                     Copyright.txt             Modules
CMakeCPack.cmake            CTestConfig.cmake         Readme.txt
CMakeCPackOptions.cmake.in  CTestCustom.cmake.in      Source
CMakeGraphVizOptions.cmake  CTestCustom.ctest.in      Templates
CMakeLists.txt              DartConfig.cmake          Tests
CMakeLogo.gif               DartLocal.conf.in         Utilities
[[email protected] cmake-2.8.6]# ./bootstrap

[[email protected] cmake-2.8.6]# make && make install

 

二.设置mysql用户组和用户

[[email protected] cmake-2.8.6]# groupadd mysql

[[email protected] cmake-2.8.6]# useradd -r -g mysql mysql

 

三. 新建mysql 所需要的数据目录

[[email protected] cmake-2.8.6]# mkdir -p /usr/local/mysql
[[email protected] cmake-2.8.6]# mkdir -p /data/mysqldb

[[email protected] soft]# tar xf mysql-5.6.35.tar.gz -C /usr/src
[[email protected] soft]# cd /usr/src/mysql-5.6.35/

 

四.编译安装mysql

[[email protected] mysql-5.6.35]# cmake -DCMAK_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DMYSQL_DATADIR=/data/mysqldb -DMYSQL_TCP_PORT=3306 -DENABLE_DOWNLOADS=1

[[email protected] mysql-5.6.35]# make && make install

 

五.修改mysql目录的所有者和属组

[[email protected] mysql-5.6.35]# chown -R mysql.mysql /data/mysqldb/
[[email protected] mysql-5.6.35]# chown -R mysql.mysql /usr/local/mysql/

 

六. 导入mysql的配置文件,以下myql配置文件根据服务器的配置不同需要做出相应的更改。

     也可以启动mysql时,根据错误日志内容做出相应的更改。

 [[email protected] etc]# egrep -v "^$|^#" ./my.cnf
[mysqld]
datadir = /data/mysqldb
port = 3306
server_id = 11
autocommit = 0
character_set_server=utf8
max_allowed_packet = 52m
max-connections = 1000
interactive_timeout = 1800
wait_timeout = 1800
read_buffer_size = 16777216
read_rnd_buffer_size = 33554432
sort_buffer_size = 33554432
tmp_table_size = 67108864
tmpdir = /tmp
log-bin=mysql-bin
binlog-format = ROW
relay-log = mysql-relay-bin
log-slave-updates = 1
read_only = 0
sync_binlog = 1 
 
plugin-load = "rpl_semi_sync_master=semisync_master.so;rpl_semi_sync_slave=semisync_slave.so"
rpl-semi-sync-master-enabled = 1
rpl-semi-sync-slave-enabled = 1
slave-skip-errors = ddl_exist_errors
relay-log-info-repository = TABLE
relay_log_recovery = 1
master_info_repository = TABLE
 
log_error = error.log
slow_query_log = 1
slow_query_log_file = slow.log
log_queries_not_using_indexes = 1
log_slow_admin_statements = 1
log_slow_slave_statements = 1
log_throttle_queries_not_using_indexes = 10
expire_logs_days = 90
long_query_time = 2
min_examined_row_limit = 100
innodb_page_size = 16384
innodb_buffer_pool_size = 4G
innodb_buffer_pool_instances = 8
innodb_buffer_pool_load_at_startup = 1
innodb_buffer_pool_dump_at_shutdown = 1
innodb_lru_scan_depth = 2000
innodb_lock_wait_timeout = 5
innodb_io_capacity = 4000
innodb_io_capacity_max = 8000
innodb_flush_method = O_DIRECT
innodb_file_format = Barracuda
innodb_file_format_max = Barracuda
innodb_undo_logs = 128
innodb_undo_tablespaces = 3
innodb_flush_neighbors = 1
innodb_log_file_size = 4G
innodb_log_buffer_size = 16777216
innodb_purge_threads = 4
innodb_large_prefix = 1
innodb_thread_concurrency = 64
innodb_print_all_deadlocks = 1
innodb_strict_mode = 1
innodb_flush_log_at_trx_commit=1 
innodb_sort_buffer_size = 67108864
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

 

 七. 初始化数据库

[[email protected] mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysqldb

 

八. 复制mysql启动脚本及加入PATH 路径

[[email protected] mysql]# cp support-files/mysql.server /etc/init.d/mysqld

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

[[email protected] mysql]# source /etc/profile

 

九 启动myql 并加入开机自启动

[[email protected] mysql]# /etc/init.d/mysqld start

[[email protected] mysql]# netstat -lnpt | grep 3306
tcp        0      0 :::3306                     :::*                        LISTEN      1361/mysqld

注:在启动mysql的时候,可能会遇到mysql 启动报错的问题,查看错误日志报:

Fatal error: Can‘t open and lock privilege tables: Table ‘mysql.user‘ doesn‘t exist
解决方法:重新执行 第七步,在重新启动mysql,错误日志继续报  
[ERROR] Aborting,执行chown -R mysql:mysql /data/mysqldb/  
chown -R mysql:mysql /usr/local/mysql/ ,在启动mysql就可以了。
 
 

 

以上是关于myql 5.6 安装的主要内容,如果未能解决你的问题,请参考以下文章

lnmp-----mysql安装----myql二进制安装

Centos6.9安装Myql数据库RPM包

myql搭建mha高可用

Centos6.5+nginx+php+myql+zabbix 配置邮件报警(qq邮箱)

Laravel 安装程序不断安装 5.5 而不是 5.6

MySQL 5.6安装