1 安装make编译器
下载地址: http://www.gnu.org/software/make/
- tar zxvf make-3.82.tar.gz
- cd make-3.82
- ./configure
- make
- make install
注释:centos中不需要安装.
2 C++编译器
http://www.gnu.org/software/gcc/
- tar zxvf gcc-c++-4.4.4.tar.gz
- cd gcc-c++-4.4.4
- ./configure
- make
- make install
注释:centos系统可直接运行: yum install gcc-c++ 安装
3 和分析器bison
下载地址: http://www.gnu.org/software/bison/
- tar zxvf bison-2.5.tar.gz
- cd bison-2.5
- ./configure
- make
- make install
注释:centos中可以直接运行命令: yum install bison 安装
4 安装前需要先安装cmake
下载地址: http://www.cmake.org/
- yum install gcc-c++
- yum install bison
- tar zxvf cmake-2.8.4.tar.gz
- cd cmake-2.8.4
- ./configure
- make
- make install
- export PATH=”$PATH:/usr/local/cmake/bin”(添加环境变量)
5 安装ncurses(字符终端处理库)
下载地址: http://www.gnu.org/software/ncurses/
- tar zxvf ncurses-5.8.tar.gz
- cd ncurses-5.8
- ./configure
- make
- make install
CentOS下用命令安装: yum install ncurses-devel
6 安装mysql
Shell> groupadd mysql
Shell> useradd -r -g mysql mysql
Shell> tar zxvf mysql-5.5.27.tar.gz
Shell> cd mysql-5.5.127
Shell> cmake . /
Cmake参数介绍:
parameter |
configure option |
cmake option |
Install base dir |
–prefix=/usr/local/mysql |
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql |
Mysqld dir |
–libexecdir=/usr/local/mysql/sbin |
-DINSTALL_SBINDIR=sbin |
Data dir |
–datadir=/mydata |
-DMYSQL_DATADIR=/mydata |
Config dir |
–sysconfdir=/etc/mysql |
-DSYSCONFDIR=/etc/mysql |
Plugin dir |
–with-plugindir=/usr/local/mysql/lib/mysql/plugin |
-DINSTALL_PLUGINDIR=lib/mysql/plugin |
Manpage dir |
–mandir=/usr/local/mysql/share/man |
-DINSTALL_MANDIR=share/man |
Shared-data dir |
–sharedstaedir=/usr/local/mysql/share/mysql |
-DINSTALL_SHAREDIR=share |
Library install dir |
–libdir=/usr/local/mysql/lib/mysql |
-DINSTALL_LIBDIR=lib/mysql |
Header install dir |
–includedir=/usr/local/mysql/include/mysql |
-DINSTALL_INCLUDEDIR=include/mysql |
Info doc dir |
–infodir=/usr/local/mysql/share/info |
-DINSTALL_INFODIR=share/info |
注释: CMAKE_INSTALL_PREFIX值是安装的基本目录,其他cmake选项值是不包括前缀,是相对路径名,绝对路径包括CMAKE_INSTALL_PREFIX路径。如-DINSTALL_SBINDIR=sbin的绝对路径是/usr/local/mysql/sbin
存储引擎选项
mysql存储引擎是插件式的,因此插件控制选项可以指定那个存储引擎安装。
configure编译插件选项–with-plugins=csv,myisam,myisammrg,heap,innobase,
archive,blackhole在cmake中没有直接对应的相同选项。对于csv,myisam,myisammrg,heap在cmake中是不需要明确指定存储引擎的名称,因为它们是强制性安装。
可以使用以下选择来安装innodb,archive,blackhole存储引擎
-DWITH_INNOBASE_STORAGE_ENGINE=1
-DWITH_ARCHIVE_STORAGE_ENGINE=1
-DWITH_BLACKHOLE_STORAGE_ENGINE=1
(1可以使用on代替)
如果既不是-DWITH_<ENGINE>_STORAGE_ENGINE 也不是 -DWITHOUT_<ENGINE>_STORAGE_ENGINE来指定存储引擎,该存储引擎将安装成共享模块式的。如果不是共享模块式的将排除在外。共享模块安装时必须使用INSTALL PLUGIN语句或–plugin-load才可以使用。
lib库选项
parameter |
configure option |
cmake option |
readline library |
–with-readline |
-DWITH_READLINE=1 |
SSL library |
–with-ssl=/usr |
-DWITH_SSL=system |
zlib library |
–with-zlib-dir/usr |
-DWITH_ZLIB=system |
Libwrap library |
–without-libwrap |
-DWITH_LIBWRAP=0 |
其他选项
之前MySQL的编译选项大多数都支持。新旧版本之间的安装选项映射成大写字母,删除选项前面破折号,中间字符间的破折号替换成下划线。如:
–with-debug => WITH_DEBUG=1
–with-embedded-server => WITH_EMBEDDED_SERVER
Parameter |
Configure option |
Cmake option |
TCP/IP port number |
–with-tcp-port=3306 |
-DMYSQL_TCP_PORT=3306 |
UNIX socket file |
–with-unix-socket-path=/tmp/mysqld.sock |
-DMYSQL_UNIX_ADDR=/tmp/mysqld.sock |
Enable LOCAL for LOAD DATA |
–enable-local-infile |
-DENABLED_LOCAL_INFILE=1 |
Extra charsets |
–with-extra-charsets=all |
-DEXTRA_CHARSETS=all |
Default charset |
–with-charset=utf8 |
-DDEFAULT_CHARSET=utf8 |
Default collation |
–with-collation=utf8_general_ci |
-DDEFAULT_COLLATION=utf8_general_ci |
Build the server |
–with-server |
none |
Build the embedded server |
–with-embedded-server |
-DWITH_EMBEDDED_SERVER=1 |
libmysqld privilege control |
–with-embedded-privilege-control |
none |
Install the documentation |
–without-docs |
none |
Big tables |
–with-big-tables, –without-big-tables |
none |
mysqld user |
–with-mysqld-user=mysql |
-DMYSQL_USER=mysql |
Debugging |
–without-debug |
-DWITH_DEBUG=0 |
GIS support |
–with-geometry |
none |
Community features |
–enable-community-features |
none |
Profiling |
–disable-profiling |
-DENABLE_PROFILING=0 |
pstack |
–without-pstack |
none |
Assembler string functions |
–enable-assembler |
none |
Build type |
–build=x86_64-pc-linux-gnu |
no equivalent |
Cross-compile host |
–host=x86_64-pc-linux-gnu |
no equivalent |
Client flag |
–with-client-ldflags=-lstdc++ |
none |
Client flag |
–enable-thread-safe-client |
none |
Comment |
–with-comment=’string’ |
-DWITH_COMMENT=’string’ |
Shared/static binaries |
–enable-shared –enable-static |
none |
Memory use |
–with-low-memory |
none |
Collation 定序也就是默认的排序方式
cmake . -DMAKE_install_prefix=/usr/local/mysql -Dsysconfdir=/etc/mysql -Dwith_innobase_storage_engine=1 -Dwith_archive_storage_engine=1 -Dwith_blackhole_storage_engine=1 -Dmysql_unix_addr=/tem/mysqld.sock -Dextra_charset=all -Ddefault_charset=utf8 -Ddefault_collation=utf8_general_ci -Dmysql_user=mysql
调试配置过程
使用configure编译完将生成config.log和config.status文件。
使用cmake编译完在CMakeFiles目录下生成CMakeError.log 和CMakeOutput.log文件。
如果编译出错 需要cmake clean
删除日志文件 rm –f CMakeError.log
Shell> make (安装mysql)
Shell> make install
Shell> cd /usr/local/mysql
Shell> chown –R mysql .(修改权限)
Shell> chgrp –R mysql .
Shell> scripts/mysql_install_db –user=mysql (初始化数据库)
Shell> cp support-files/my-medium.cnf /etc/my.cnf (可选拷贝配置文件)
Shell> cp support-files/mysql.server /etc/init.d/mysql.server
Shell>service mysql.server start
Shell>service mysql.server stop
Shell> chkconfig –add mysql.server(添加到开机启动项)
Shell> ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock (创建sock文件软连接)
Shell>mysql –u root –p (进入mysql)
Mysql>update set Password=PASSWPRD(‘sa’) where User=’root’;(设置密码)
Mysql>flush privileges;(让服务器重新读取授权表,密码才生效)
7 遇到的问题:
1.启动mysql服务出错: /etc/init.d/mysql start
Starting MySQL.The server quit without updating PID file (/usr/local/mysql/data/localhost.localdomain.pid).
解决方案:
在 my.cnf 中增加了 在server下面
# The MySQL server
[mysqld]
port = 3306
socket = /tmp/mysql.sock(sock连接mysql)
添加下面一行
datadir = /var/lib/mysql/
log—slow-queries=/var/log/hostname-slow.log(开启慢查询日志)
long-query-time=1(慢查询时间设置);
query-cache-size(缓存query大小)
和
[safe_mysqld]
log-error = /var/log/mysqld.log(开启错误日志)
pid-file = /var/lib/mysql/localhost.localdomain.pid(进程文件)
2,运行mysql出错: 'Can't connect to local MySQL server through socket '/tmp/mysql.sock'
解决方案:增加软连接: ln -s /tmp/mysql.sock /var/lib/mysql/mysql.sock
添加PATH路径:
export PATH="$PATH:/usr/local/mysql /bin"
vi /etc/profile
#vi ~/.bash_profile PATH=$PATH:$HOME/bin:/usr/local/mysql/bin
8 mysql服务器基本优化:
- 1. 开启错误日志:
- 2. log-error = /var/log/mysqlerror
- 3. 开启慢查询日志
- 4. log-slow-queries=/var/log/slowlog
- 5. 开启二进制日志
- 6. log-bin=bin-log
+--------------------------------+------------+
| Variable_name | Value |
+--------------------------------+------------+
| binlog_cache_size | 1048576 |
| innodb_locks_unsafe_for_binlog | OFF |
| max_binlog_cache_size | 4294967295 |
| max_binlog_size | 1073741824 |
| sync_binlog | 0 |
+--------------------------------+------------+
“binlog_cache_size":在事务过程中容纳二进制日志SQL 语句的缓存大小。
“max_binlog_cache_size”:和"binlog_cache_size"相对应,但是所代表的是binlog 能够使用的最大cache 内存大小
“max_binlog_size”:Binlog 日志最大值,一般来说设置为512M 或者1G,但不能超过1G
● sync_binlog=0,当事务提交之后,MySQL 不做fsync 之类的磁盘同步指令刷新binlog_cache 中的信息到磁盘,而让Filesystem 自行决定什么时候来做同步,或者cache 满了之后才同步到磁盘。
● sync_binlog=n,当每进行n 次事务提交之后,MySQL 将进行一次fsync 之类的磁盘同步指令来将binlog_cache 中的数据强制写入磁盘。在MySQL 中系统默认的设置是sync_binlog=0,也就是不做任何强制性的磁盘刷新指令,这时候的性能是最好的,但是风险也是最大的。因为一旦系统Crash,在binlog_cache 中的所有binlog 信息都会被丢失。而当设置为“1”的时候,是最安全但是性能损耗最大的设置。因为当设置为1 的时候,即使系统Crash,也最多丢失binlog_cache 中未完成的一个事务,对实际数据没有任何实质性影响。从以往经验和相关测试来看,对于高并发事务的系统来说,“sync_binlog”设置为0 和设置为1 的系统写入性能差距可能高达5 倍甚至更多。
Query cache配置优化: set global query_cache=50M即可.
在my.cnf中增加: query-cache-size = 50M
Query-cahce-min-res-unit=1024(具体值可以根据query_cache_size-Qcache_free_memory)/Qcache_queries_in_cache
最多链接数:
max-connection=500-800;
thread_cache_size=50-100
thread_stack:每个连接线程被创建的时候,MySQL 给他分配的内存大小。使用系统的默认值(192KB)基本上可以所有的普通应用环境。如果该值设置太小,会影响MySQL 连接线程能够处理客户端请求的Query 内容的大小,以及用户创建的Procedures 和Functions 等。