标签:linux mysql mysql 5.6 centos 6.8
安装环境:Centos 6.8,mysql 5.6.23
一、编译安装MySQL前准备工作
安装编译源码所需的工具和库
yum -y install gcc gcc-c++ ncurses-devel perl openssl-devel bison
安装cmake(记得好像从mysql 5.5开始需要cmake编译安装),可从https://cmake.org/download/ 中下载。
tar zxvfcmake-3.4.1.tar.gz cd cmake-3.4.1 ./bootstrap make && make install
二、创建用户及MySQL所需目录
新增mysql用户
groupadd -r mysql useradd -r -g mysql mysql
新建MySQL所需目录
mkdir -p /usr/local/mysql mkdir -p /data/mysqldb
数据库文件目录创建可参照http://zhoufan.blog.51cto.com/4278592/1790308创建LVM并挂载。
三、编译安装MySQL
可从http://dev.mysql.com/downloads/mysql/ 下载mysql源码。
tar zxvf mysql-5.6.23.tar.gz cd mysql-5.6.23 cmake-DCMAKE_INSTALL_PREFIX=/usr/local/mysql -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 -DSYSCONFDIR=/etc\ -DWITH_SSL=system -DWITH_ZLIB=system\ -DWITH_LIBWRAP=0 make&& make install
-DCMAKE_INSTALL_PREFIX=dir_name | 设置mysql安装目录 |
-DDEFAULT_CHARSET=charset_name | 设置服务器的字符集。缺省情况下,MySQL使用latin1的(CP1252西欧)字符集 |
-DDEFAULT_COLLATION=collation_name | 设置服务器的排序规则。 |
-DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 | 存储引擎选项:MyISAM,MERGE,MEMORY,和CSV引擎是默认编译到服务器中,并不需要明确地安装。 |
-DMYSQL_DATADIR=dir_name | 设置mysql数据库文件目录 |
-DSYSCONFDIR | 设置my.cnf位置 |
修改mysql目录权限
cd /usr/local/mysql chown -R mysql:mysql . cd /data/mysqldb chown -R mysql:mysql .
初始化mysql数据库
cd/usr/local/mysql scripts/mysql_install_db--user=mysql --datadir=/data/mysqldb
编辑MySQL配置文件
mv /etc/my.cnf /etc/my.cnf.bak
编辑my.cnf,my.cnf可在percona官网中及按照自己的情况生成。网址如下:https://tools.percona.com/wizard 。
[mysql] # CLIENT # port = 3306 socket = /data/mysqldb/mysql.sock [mysqld] # GENERAL # user = mysql default-storage-engine = InnoDB socket = /data/mysqldb/mysql.sock pid-file = /data/mysqldb/mysql.pid # MyISAM # key-buffer-size = 32M myisam-recover = FORCE,BACKUP # SAFETY # max-allowed-packet = 16M max-connect-errors = 1000000 # DATA STORAGE # datadir = /data/mysqldb/ # BINARY LOGGING # log-bin = /data/mysqldb/mysql-bin expire-logs-days = 14 sync-binlog = 1 # REPLICATION # skip-slave-start = 1 relay-log = /data/mysqldb/relay-bin slave-net-timeout = 60 # CACHES AND LIMITS # tmp-table-size = 32M max-heap-table-size = 32M query-cache-type = 0 query-cache-size = 0 max-connections = 500 thread-cache-size = 50 open-files-limit = 65535 table-definition-cache = 4096 table-open-cache = 4096 # INNODB # innodb-flush-method = O_DIRECT innodb-log-files-in-group = 2 innodb-log-file-size = 64M innodb-flush-log-at-trx-commit = 1 innodb-file-per-table = 1 innodb-buffer-pool-size = 592M # LOGGING # log-error = /data/mysqldb/mysql-error.log log-queries-not-using-indexes = 1 slow-query-log = 1 slow-query-log-file = /data/mysqldb/mysql-slow.log
复制MySQL启动文件及其命令加入PATH
cp support-files/mysql.server /etc/init.d/mysqld vim /etc/profile.d/mysql.sh PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH export PATH source /etc/profile.d/mysql.sh
启动MySQL并增加启动项
service mysqld start chkconfig mysqld on
设置MySQL登录权限
drop user ‘‘@localhost; drop user ‘‘@hostname; update mysql.user set password=password(‘*******‘); flush privileges;
至此,MySQL编译安装完成。
本文出自 “Frank” 博客,请务必保留此出处http://zhoufan.blog.51cto.com/4278592/1790330
标签:linux mysql mysql 5.6 centos 6.8
原文地址:http://zhoufan.blog.51cto.com/4278592/1790330