当前位置: > CentOS > CentOS教程 >

64位centos6中安装、配置mysql5.6.x的教程

时间:2014-11-27 01:55来源:linux.it.net.cn 作者:IT

介绍下在centos6的64位系统下,安装与配置mysql5.6.x的方法。

首先,yum安装需要的包:
 

复制代码代码示例:
yum -y install wget gcc-c++ ncurses-devel cmake make perl opensslopenssl-devel ncurses ncurses-devel bison libxml2 libxml2-devel curl-devel libjpeg-devel libpng-devel freetype freetype-devel

第二步:关闭itables和SELINUX,
 

复制代码代码示例:
# service iptables stop
# setenforce 0
# vi /etc/sysconfig/selinux
-------------------
SELINUX=disabled
-------------------

第三步:准备安装目录等工作
 

复制代码代码示例:
# useradd -d /usr/local/mysql/ mysql   #创建一个Mysql用户,指定家目录到/use/local目录下。
# mkdir /usr/local/mysql/data          
# mkdir /usr/local/mysql/log           #新建mysql下data和log子目录
# chown -R mysql:mysql /usr/local/mysql/data/
# chown -R mysql:mysql /usr/local/mysql/log/
# chmod 750 /usr/local/mysql/data      
# chmod 750 /usr/local/mysql/log       #修改目录的所属者以及所属组

第四步:解压源码包并编译
 

复制代码代码示例:

# tar -zxv -f mysql-5.6.10.tar.gz      
# cd mysql-5.6.10  
# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock \
-DDEFAULT_CHARSET=gbk \
-DDEFAULT_COLLATION=gbk_chinese_ci \
-DEXTRA_CHARSETS=all \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_FEDERATED_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DENABLED_LOCAL_INFILE=1 \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DMYSQL_USER=mysql \
-DMYSQL_TCP_PORT=3306 \
-DSYSCONFDIR=/etc \
-DWITH_SSL=yes \
-DENABLE_DOWNLOADS=1

#  make & make install

编译注解:
 

-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \         #安装目录
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock \               #Unix socket文件路径,自定义此路径防报错
-DDEFAULT_CHARSET=gbk \                           #默认字符
-DDEFAULT_COLLATION=gbk_chinese_ci \              #校验字符
-DEXTRA_CHARSETS=all \                            #安装所有扩展字符集
-DWITH_MYISAM_STORAGE_ENGINE=1 \                  #安装myisam存储引擎
-DWITH_INNOBASE_STORAGE_ENGINE=1 \                #安装innodb存储引擎
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \                 #安装archive存储引擎
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \               #安装blackhole存储引擎
-DWITH_MEMORY_STORAGE_ENGINE=1 \                  #安装memory存储引擎
-DWITH_FEDERATED_STORAGE_ENGINE=1                 #安装frderated存储引擎
-DWITH_READLINE=1 \                               #快捷键功能
-DENABLED_LOCAL_INFILE=1 \                        #允许从本地导入数据
-DMYSQL_DATADIR=/usr/local/mysql/data \           #数据库存放目录
-DMYSQL_USER=mysql \                              #数据库属主
-DMYSQL_TCP_PORT=3306 \                           #数据库端口
-DSYSCONFDIR=/etc \                               #MySQL配辑文件
-DWITH_SSL=yes                                    #数据库SSL

编译过程中可能会报一个gmock错误,去mysql解压目录下的source_downloads下,用unzip解压gmock的zip包,然后回到mysql解压根目录继续执行cmake编译命令,问题即可解决。

第五步:编辑my.cnf文件,vim /etc/my.cnf
 

复制代码代码示例:

[mysql]

# CLIENT #
port                           = 3306
socket                         = /tmp/mysql.sock

[mysqld]

# GENERAL #
user                           = mysql
default_storage_engine         = InnoDB
socket                         = /tmp/mysql.sock
pid_file                       = /var/run/mysqld/mysqld.pid

# MyISAM #
key_buffer_size                = 32M
myisam_recover                 = FORCE,BACKUP

# SAFETY #
max_allowed_packet             = 16M
max_connect_errors             = 1000000
skip_name_resolve
sql_mode                       = STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_AUTO_VALUE_ON_ZERO,NO_ENGINE_SUBSTITUTION,
NO_ZERO_DATE,NO_ZERO_IN_DATE,ONLY_FULL_GROUP_BY
sysdate_is_now                 = 1
innodb                         = FORCE
innodb_strict_mode             = 1

# DATA STORAGE #
datadir                        = /usr/local/mysql/data

# BINARY LOGGING #
log-bin                        =/usr/local/mysql/log/bin.log
expire_logs_days               = 30
sync_binlog                    = 1

# CACHES AND LIMITS #
key_buffer                     = 256M
max_allowed_packet             = 32M
sort_buffer_size               = 16M
read_buffer_size               = 4M
read_rnd_buffer_size           = 16M
thread_stack                   = 8M
tmp_table_size                 = 32M
max_heap_table_size            = 32M
query_cache_type               = 1
query_cache_size               = 128M
query_cache_limit              = 2M
max_connections                = 2048
thread_cache_size              = 512
open_files_limit               = 65535
table_definition_cache         = 1024
table_open_cache               = 2048

# INNODB #
innodb_log_files_in_group      = 2
innodb_log_file_size           = 64M
innodb_flush_log_at_trx_commit = 1
innodb_file_per_table          = 1
# 2G这个值配置低的话建议改小即可
innodb_buffer_pool_size        = 2G

# LOGGING #
log-error=/usr/local/mysql/log/error.log
general_log=1
general_log_file=/usr/local/mysql/log/mysql.log
slow_query_log=1
slow_query_log_file=/usr/local/mysql/log/slowquery.log
log-output=FILE

# 避免MySQL的外部锁定,减少出错几率增强稳定性 #
skip-external-locking

# 禁止sql读取本地文件 #
local-infile=0

说明:
因为使用的是阿里云69元的服务器。# CACHES AND LIMITS #这块配置需要注释掉,不然无法启动mysql,并报pid文件错误,innodb_buffer_pool_size这个改成了只有16M了。

第六步:

将mysql的库文件路径加入系统的库文件搜索路径中
方法一:直接做软链接
 

复制代码代码示例:
# ln -s /usr/local/mysql/lib/mysql /usr/lib/mysql
 

方法二:利用ldconfig导入系统库
 

复制代码代码示例:
# echo "/usr/local/mysql/lib" >> /etc/ld.so.conf.d/mysql.conf
# ldconfig

输出mysql的头文件到系统头文件
 

复制代码代码示例:
# ln -s /usr/local/mysql/include/mysql /usr/include/mysql

进入安装路径,初始化配置脚本
 

复制代码代码示例:
# cd /usr/local/mysql
# scripts/mysql_install_db --user=mysql --datadir=/usr/local/mysql/data

复制mysql启动脚本到系统服务目录
 

复制代码代码示例:
# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld

系统启动项相关配置
 

复制代码代码示例:
# chkconfig --add mysqld  #添加开机启动服务
# chkconfig --level 35 mysqld on  #设置mysql启动

启动mysql
 

复制代码代码示例:
# service mysqld start

注:编译时若socket路径自定义为/var/lib/mysql/mysql.sock,这里需要创建一个mysql接口的软链接,防止登陆后台或安装论坛报错.
 

复制代码代码示例:
# ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock 

设置初始账户,并登陆后台:
 

复制代码代码示例:
# /usr/local/mysql/bin/mysqladmin -u root password 123456   #设置密码
# /usr/local/mysql/bin/mysql -u root -p123456     #连接数据库

到这里,就完成了在centos6中安装与配置mysql5.6.x,希望对大家有一定的帮助。



(责任编辑:IT)
------分隔线----------------------------
栏目列表
推荐内容