MySQL版本介绍和安装---JC MySQL系列(二)
(一)MYSQL版本介绍:MySQL 4.1/5.0/5.1/5.5/5.6各版本的主要区别
1.mysql-server-4.1
增加了子查询的支持,字符集增加UTF-8,GROUP BY语句增加了ROLLUP,mysql.user表采用了更好的加密算法,innodb开始支持单独的表空间。
2.mysql-server-5.0
增加了Stored procedures、Views、Cursors、Triggers、XA transactions的支持,增加了INFORATION_SCHEMA系统数据库。
3.mysql-server-5.1
增加了Event scheduler,Partitioning,Pluggable storage engine API ,Row-based replication、Global级别动态修改general query log和slow query log的支持。
小版本的重要特性:
4.mysql-5.1.2 开始支持微秒级的慢查询。关于慢查询相关信息请参考 http://linuxguest.blog.51cto.com/195664/721042
5.mysql-server-5.5
1)默认存储引擎更改为InnoDB
2)提高性能和可扩展性
a. 提高了默认线程并发数(innodb_thread_concurrency)
b. 后台输入/输出线程控制(innodb_read_io_threads、innodb_write_io_threads)
c. 主线程输入/输出速率控制(innodb_io_capacity)
d. 操作系统内存分配程序使用控制(innodb_use_sys_malloc)
e. 适应性散列索引(Hash Index)控制,用户可以关闭适应性散列功能。
f. 插入缓冲(Insert Buffering)控制,用户可以关闭innodb的插入缓冲功能。
g. 通过快速加锁算法提高可扩展性,innodb不在使用代理(posix)线程,而是使用原生的独立操作来完成互斥和读写锁定。
h. 恢复组提交(Restored Group Commit)
i. 提高恢复性能
j. 多缓冲池实例
k. 多个回滚段(Multiple Rollback Segments),之前的innodb版本最大能处理1023个并发处理操作,现在mysql5.5可以处理高达128K的并发事物,
l. Linux系统固有的异步输入/输出,mysql5.5数据库系统也提高了linux系统的输入输出请求的并发数。
m. 扩展变化缓冲:添加了删除缓冲和清除缓冲
n. 改善了日志系统互斥和单独刷新(Flush)列表互斥
o. 改善清除程序进度,在mysql5.5中清楚操作线程是独立的线程,并支持并发,可以使用innodb_purge_treads配置。
p. 改善事务处理中的元数据锁定。例如,事物中一个语句需要锁一个表,会在事物结束时释放这个表,而不是像以前在语句结束时释放表。
3)提高实用性
a. 半同步复制(Semi-synchronous Replication)
b. 复制Heartbeat
c. 中继日志自动恢复(Automatic> d. 根据服务器过滤项复制(Replication Per Server Filtering)
e. 从服务器复制支持的数据类型转换(Replication Slave Side Data Type Conversions)
4)提高易管理性和效率
a. 建立快速索引(Faster Index Creation)
b. 高效的数据压缩(Efficient Data Compression)
c. 为大物件和可变长度列提供高效存储
d. 增加了INFORMATION_SCHEMA表,新的表提供了与InnoDB压缩和事务处理锁定有关的具体信息。
5)提高可用性
a. 针对SIGNAL/RESIGNAL的新SQL语法
b. 新的表/索引分区选项。MySQL5.5将表和索引RANG和LIST分区范围扩展到了非整数列和日期,并增加了在多个列上分区的能力。
6)改善检测和诊断
Mysql5.5引入了一种新的性能架构(performancn_shema,P_S),用于监控mysql监控服务器运行时的性能。
小版本的重要特性:
percona-server-5.5.18.23支持group commit 参考:http://www.orczhou.com/index.php/2011/12/time-to-group-commit-2/
mysql-server-5.6
1)InnoDB现在可以限制大量表打开的时候内存占用过多的问题(比如这里提到的)(第三方已有补丁)
2)InnoDB性能加强。如分拆kernel mutex;flush操作从主线程分离;多个perge线程;大内存优化等
3)InnoDB死锁信息可以记录到 error 日志,方便分析
4)MySQL5.6支持延时复制,可以让slave跟master之间控制一个时间间隔,方便特殊情况下的数据恢复。
5)表分区功能增强
6)MySQL行级复制功能加强,可以降低磁盘、内存、网络等资源开销(只记录能确定行记录的字段即可)
7)Binlog实现 crash-safe
8)复制事件采用crc32校验,增强master/slave 复制数据一致性
9)新增 log_bin_basename (以前variables里面没有binlog位置信息,对数据库的监管很不方便)
(二)安装MySQL
备注:mysql安装有2种方式:
1)编译安装
2)yum安装
#我这里采用的是编译安装MYSQL,系统环境是:
# cat /etc/redhat-release
CentOS> # uname -i
x86_64
#这里采用Centos6.2 X86_64位操作系统.
#先yum安装依赖:
# yum -y install gcc* make libXp* gcc-c++ autoconfbisonncurses ncurses-devel openssl openssl-devel
# [ ! -d /tools ] && mkdir -p /tools
#什么是bison?
BISON用于语法分析器的自动生成,实际上可用于所有常见的操作系统。Bison把LALR形式的上下文无关文法描述转换为可做语法分析的C或C++程序。
# wget -P /tools/ -c http://ftp.gnu.org/gnu/bison/bison-2.5.tar.gz && echo "bison-2.5.tar.gz download is OK"
# tar -zxvf /tools/bison-2.5.tar.gz -C /tools/
# cd /tools/bison-2.5
# ./configure && make && make install
#什么是cmake?
CMake是一个比make更高级的编译配置工具,它可以根据不同平台、不同的编译器,生成相应的Makefile或者vcproj项目.
#安装Cmake
# wget -P /tools/ -c http://www.cmake.org/files/v2.8/cmake-2.8.4.tar.gz && echo "cmake-2.8.4.tar.gz download is OK"
# tar -zxvf /tools/cmake-2.8.4.tar.gz -C /tools/
# cd /tools/cmake-2.8.4
# ./configure && gmake && gmake install
#安装MySQL5.5.19
# wget -P /tools/ -c http://down1.chinaunix.net/distfiles/mysql-5.5.19.tar.gz && echo "mysql-5.5.19.tar.gz download is OK"
# tar -zxvf /tools/mysql-5.5.19.tar.gz -C /tools/
# cd /tools/mysql-5.5.19
# groupadd mysql
# useradd -g mysql mysql
# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STOPAGE_ENGINE=1 -DWITH_BLACKHOLE_STOPAGE_ENGINE=1 -DENABLED_LOCAL_INFILE=1 -DMYSQL_DATADIR=/var/mysql/data -DMYSQL_USER=mysql -DMYSQL_TCP-PORT=3306
参数说明:
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql //安装目录
-DMYSQL_DATADIR=/var/mysql/data数据库存放目录
-DWITH_MYISAM_STORAGE_ENGINE=1 //安装myisam存储引擎
-DWITH_INNOBASE_STORAGE_ENGINE=1 //安装innodb存储引擎
-DWITH_ARCHIVE_STORAGE_ENGINE=1 //安装archive存储引擎
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 //安装blackhole存储引擎
-DENABLED_LOCAL_INFILE=1 //允许从本地导入数据
-DDEFAULT_CHARSET=utf8 //使用utf8字符
-DDEFAULT_COLLATION=utf8_general_ci //校验字符
-DEXTRA_CHARSETS=all //安装所有扩展字符集
-DMYSQL_TCP_PORT=3306 //MySQL监听端口
-DMYSQL_USER=mysql //MySQL用户名
其他参数:
-DWITH-EMBEDDED_SERVER=1 //编译成embedded MySQL library (libmysqld.a)
-DSYSCONFDIR=/etc //MySQL配辑文件
-DMYSQL_UNIX_ADDR=/tmp/mysqld.sock //Unix socket 文件路径
-DWITH_READLINE=1 //快捷键功能
-DWITH_SSL=yes //SSL
-DWITH_MEMORY_STORAGE_ENGINE=1 //安装memory存储引擎
-DWITH_FEDERATED_STORAGE_ENGINE=1 //安装frderated存储引擎
-DWITH_PARTITION_STORAGE_ENGINE=1 //安装数据库分区
-DINSTALL_PLUGINDIR=/usr/local/mysql/plugin //插件文件及配置路径
# make && make install
# chmod +w /usr/local/mysql
# chown -R mysql:mysql /usr/local/mysql
# ln -s /usr/local/mysql/lib/libmysqlclient_r.so.18.0.0 /usr/
# mkdir -p /var/mysql/
# mkdir -p /var/mysql/data/
# mkdir -p /var/mysql/log/
# chown -R mysql:mysql /var/mysql/
# cd support-files/
# cp my-large.cnf /var/mysql/my.cnf
# cp mysql.server /etc/init.d/mysqld
#初始化安装
# /usr/local/mysql/scripts/mysql_install_db --defaults-file=/var/mysql/my.cnf --basedir=/usr/local/mysql/ --datadir=/var/mysql/data/ --user=mysql
# chmod +x /etc/init.d/mysqld
# vim /etc/init.d/mysqld +46
在 basedir=/usr/local/mysql#(添加)mysql安装目录
datadir=/var/mysql/data #(添加)mysql数据存储目录
#设置mysql开机启动
# chkconfig --add mysqld
# chkconfig --level 345 mysqld on
#启动mysql服务进程
# vim /var/mysql/my.cnf +28
#注释skip-federated
# rm -f /etc/my.cnf
# /etc/init.d/mysqld restart
# ln -s /usr/local/mysql/bin/* /bin/
# cd
# mysqladmin -uroot password '123456' #设置mysql初始密码
# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor.Commands end with ; or \g.
Your MySQL connection> Server version: 5.5.19 Source distribution
Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show engines; #InnoDB是MYSQL5.5系列默认的存储引擎.
+--------------------+---------+------------------------------------------------------------+--------------+------+------------+
| Engine | Support | Comment | Transactions | XA | Savepoints |
+--------------------+---------+------------------------------------------------------------+--------------+------+------------+
| MyISAM | YES | MyISAM storage engine | NO | NO | NO |
| InnoDB | DEFAULT | Supports transactions, row-level locking, and foreign keys | YES | YES| YES |
| MRG_MYISAM | YES | Collection of> | PERFORMANCE_SCHEMA | YES | Performance Schema | NO | NO | NO |
| CSV | YES | CSV storage engine | NO | NO | NO |
| MEMORY | YES | Hash based, stored in memory, useful for temporary tables| NO | NO | NO |
+--------------------+---------+------------------------------------------------------------+--------------+------+------------+
6 rows in set (0.00 sec)
mysql> \q #退出mysql数据库.
Bye
######修改MYSQL密码#########
# mysqladmin -uroot -p123456 password '23456' #把初始设置的密码123456更改为23456
#####如果本地的mysql.sock(UNIX)套接字丢失,可以使用TCP协议进程登陆MYSQL数据库#####
# mysql -uroot -p #
Enter password:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)#错误提示不能通过/tmp/mysql.sock连接mysql server
# netstat -lntp|grep mysqld #mysqld进程是存在和启动的,问题的引起是mysql.sock丢失了。
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 14940/mysqld
#备注:从MySQL 4.1 开始,通过--protocol= TCP |SOCKET | PIPE | MEMORY}选项,你可以显示地指定连接协议.
# mysql --protocol=TCP -uroot -p -P3306
Enter password:
Welcome to the MySQL monitor.Commands end with ; or \g.
Your MySQL connection> Server version: 5.5.19 Source distribution
Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show engines;
+--------------------+---------+------------------------------------------------------------+--------------+------+------------+
| Engine | Support | Comment | Transactions | XA | Savepoints |
+--------------------+---------+------------------------------------------------------------+--------------+------+------------+
| MyISAM | YES | MyISAM storage engine | NO | NO | NO |
| InnoDB | DEFAULT | Supports transactions, row-level locking, and foreign keys | YES | YES| YES |
| MRG_MYISAM | YES | Collection of> | PERFORMANCE_SCHEMA | YES | Performance Schema | NO | NO | NO |
| CSV | YES | CSV storage engine | NO | NO | NO |
| MEMORY | YES | Hash based, stored in memory, useful for temporary tables| NO | NO | NO |
+--------------------+---------+------------------------------------------------------------+--------------+------+------------+
6 rows in set (0.00 sec)
mysql> \q
Bye
#查看MySQL的日志文件:日志文件一般是这样的格式:*.err.
# cd /var/mysql/data/
# tail -f dba01.err
1305255:02:12 InnoDB: Mutexes and rw_locks use GCC atomic builtins
1305255:02:12 InnoDB: Compressed tables use zlib 1.2.3
1305255:02:12 InnoDB: Initializing buffer pool,> 1305255:02:12 InnoDB: Completed initialization of buffer pool
1305255:02:12 InnoDB: highest supported file format is Barracuda.
1305255:02:12InnoDB: Waiting for the background threads to start
1305255:02:13 InnoDB: 1.1.8 started; log sequence number 1595675
1305255:02:13 Event Scheduler: Loaded 0 events
1305255:02:13 /usr/local/mysql/bin/mysqld: ready for connections.
Version: '5.5.19'socket: '/tmp/mysql.sock'port: 3306Source distribution
#从以上的日志信息,我们可以得知Mysql的启动程序主配置文件在/usr/local/mysql/bin/mysqld下面。MySQL版本是:5.5.19,端口号是3306,并已启动,和默认的存储引擎是InnoDB等信息。
页:
[1]