CentOS> [root@qbPC ~]# uname -a
Linux qbPC 2.6.32-431.el6.x86_64 #1 SMP Fri Nov 22 03:15:09 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
我在6.8系统也装成功了,应该6.x系列应该差不多 准备:
[root@qbPC ~]# cat /etc/udev/rules.d/70-persistent-net.rules
[root@qbPC ~]#> /etc/udev/rules.d/70-persistent-net.rules 1.3安装相关软件包 1.3.1cmake软件
#cd /home/tools/
#tar xf cmake-2.8.8.tar.gz
#cd cmake-2.8.8
#./configure
------------------------------------------------------------------------------------------ 这里可能遇见问题1:
---------------------------------------------
CMake 3.1.1, Copyright 2000-2015 Kitware, Inc.
C compiler on this system is: cc
---------------------------------------------
Error when bootstrapping CMake:
Cannot find appropriate C++ compiler on this system.
Please specify one using environment variable CXX.
See cmake_bootstrap.log for compilers attempted. 解决:
yum install make cmake gcc gcc-c++ -y
------------------------------------------------------------------------------------------
gmake
gmake install
cd .. 1.3.2依赖包
[root@qbPC tools]# yum -y install ncurses-devel
不安装会有问题:
1.4开始安装MySQL
查看系统中是否已安装 MySQL 服务:
rpm -qa | grep mysql
或
yum list installed | grep mysql
如果已安装则删除 MySQL 及其依赖的包:
yum -y remove mysql-libs.x86_64
[root@qbPC mysql-5.5.32]# make && make install
时间比较长
------------------------------------------------------------------------------------------
可能遇见问题2
解决
[root@qbPC mysql-5.5.32]# which cmake
/usr/local/bin/cmake
检查
cmake安装不正确,重新安装
------------------------------------------------------------------------------------------
编译完成
which will also give you the option of removing the test
databases and anonymous user created by default. This is
strongly recommended for production servers.
See the manual for more instructions.
启动
You can start the MySQL daemon with:
cd /application/mysql/ ; /application/mysql//bin/mysqld_safe &
测试
You can test the MySQL daemon with mysql-test-run.pl
cd /application/mysql//mysql-test ; perl mysql-test-run.pl
汇报bug
Please report any problems with the /application/mysql//scripts/mysqlbug script!
对于第一句的warning,解决
[root@qbPC scripts]# vim /etc/hosts
127.0.0.1 localhost qbPC---最后面加上主机名即可
当各种正常,在mysql的时候或者mysql -uroot -p123也不能进行,就要想想是不是初始化文件是否正确!
mysql -uroot -p123:这样登录也不行的时候进行下面操作
pkill mysqld
lsof -i :3306
rm -rf /application/mysql/data/*
然后重复4.初始化数据文件(容易出错的步骤) 7.成功登录 先优化,安全,木桶原则
[root@qbPC mysql-5.5.32]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.5.32 Source distribution
Copyright (c) 2000, 2013, 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> select user,host from mysql.user;
+------+-----------+
| user | host |
+------+-----------+
| root | 127.0.0.1 |
| root | ::1 |
| | localhost |
| root | localhost |
| | qbPC |
| root | qbPC |
+------+-----------+
6 rows in set (0.00 sec)
mysql> delete from mysql.user;
Query OK, 2 rows affected (0.00 sec)
mysql> grant all privileges on *.* to root@'localhost' identified by '***' with grant option;
Query OK, 1 row affected (0.00 sec)
mysql> select user,host from mysql.user;
+------+-----------+
| user | host |
+------+-----------+
| root | localhost |
+------+-----------+
4 rows in set (0.00 sec)
mysql> drop database test;
Query OK, 0 rows affected (0.00 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
+--------------------+
3 rows in set (0.00 sec)
mysql> 修改密码
[root@qbPC mysql-5.5.32]# /application/mysql//bin/mysqladmin -u root password '123'
[root@qbPC mysql-5.5.32]# mysql -uroot -p123
Welcome to the MySQL monitor. Commands end with ; or \g. 字符集:
[root@qbPC ~]# cat /etc/sysconfig/i18n
LANG="en_US.UTF-8"
SYSFONT="latarcyrheb-sun16"
问题:
> ALTER USER l 'jeffrey'@'localhost' ACCOUNT UNLOCK; 2.2 灵活性
在这一节,我将介绍MySQL 5.7的两个全新的功能,即JSON和generate column。充分使用这两个功能,能够极大地提高数据存储的灵活性。 2.2.1 JSON
随着非结构化数据存储需求的持续增长,各种非结构化数据存储的数据库应运而生(如MongoDB)。从最新的数据库使用 排行榜 来看,MongoDB已经超过了PostgreSQL,其火热程度可见一斑。
各大关系型数据库也不甘示弱,纷纷提供对JSON的支持,以应对非结构化数据库的挑战。MySQL数据库从5.7.8版本开始,也提供了对JSON的支持。其使用方式如下:
CREATE TABLE t1 (jdoc JSON);
INSERT INTO t1 VALUES('{"key1": "value1", "key2": "value2"}');
MySQL对支持JSON的做法是,在server层提供了一堆便于操作JSON的函数,至于存储,就是简单地将JSON编码成BLOB,然后交由存储引擎层进行处理,也就是说,MySQL 5.7的JSON支持与存储引擎没有关系,MyISAM 存储引擎也支持JSON 格式。
MySQL支持JSON以后,总是避免不了拿来与MongoDB进行一些比较。但是,MySQL对JSON的支持,至少有两点能够完胜MongoDB:
1.可以混合存储结构化数据和非结构化数据,同时拥有关系型数据库和非关系型数据库的优点
2.能够提供完整的事务支持 2.2.2 generate column
generated column是MySQL 5.7引入的新特性,所谓generated column,就是数据库中这一列由其他列计算而得。
例如,知道直角三角形的两条直角边,要求直角三角形的面积。很明显,面积可以通过两条直角边计算而得,那么,这时候就可以在数据库中只存放直角边,面积使用generated column,如下所示:
CREATE TABLE triangle (sidea DOUBLE, sideb DOUBLE, area DOUBLE AS (sidea * sideb / 2));
insert into triangle(sidea, sideb) values(3, 4);
select * from triangle;
+-------+-------+------+
| sidea | sideb | area |
+-------+-------+------+
| 3 | 4 | 6 |
+-------+-------+------+
在MySQL 5.7中,支持两种generated column,即virtual generated column和stored generated column,前者只将generated column保存在数据字典中(表的元数据),并不会将这一列数据持久化到磁盘上;后者会将generated column持久化到磁盘上,而不是每次读取的时候计算所得。很明显,后者存放了可以通过已有数据计算而得的数据,需要更多的磁盘空间,与virtual column相比并没有优势。因此,在不指定generated column的类型时,默认是virtual column,如下所示:
show create table triangle\G
*************************** 1. row ***************************
Table: triangle
Create Table: CREATE TABLE `triangle` (
`sidea` double DEFAULT NULL,
`sideb` double DEFAULT NULL,
`area` double GENERATED ALWAYS AS (((`sidea` * `sideb`) / 2)) VIRTUAL
) ENGINE=InnoDB DEFAULT CHARSET=latin1
如果读者觉得generate column提供的功能,也可以在用户代码里面实现,并没有什么了不起的地方,那么,或许还有一个功能能够吸引挑剔的你,那就是为generate column创建索引。在这个例子中,如果我们需要根据面积创建索引以加快查询,就无法在用户代码里面实现,使用generate column就变得非常简单:
alter table triangle add index ix_area(area); 2.3 易用性
易用性是数据库永恒的话题,MySQL也在持续不断地提高数据库的易用性。在MySQL 5.7中,有很多易用性方面的改进,小到一个客户端快捷键 ctrl+c 的使用,大到专门提供一个系统库(sys)来帮助DBA和开发人员使用数据库。这一节将重点介绍MySQL 5.7引入的sys库。
在linux下,我们经常使用 ctrl+c 来终止一个命令的运行,在MySQL 5.7 之前,如果用户输入了错误的SQL语句,按下 ctrl+c ,虽然能够”结束”SQL语句的运行,但是,也会退出当前会话,MySQL 5.7对这一违反直觉的地方进行了改进,不再退出会话。
MySQL 5.7可以explain一个正在运行的SQL,这对于DBA分析运行时间较长的语句将会非常有用
在MySQL 5.7中,performance_schema提供了更多监控信息,包括内存使用,MDL锁,存储过程等 2.3.1 sys schema
sys schema是MySQL 5.7.7中引入的一个系统库,包含了一系列视图、函数和存储过程, 该项目专注于MySQL的易用性。例如,我们可以通过sys schema快速的知道,哪些语句使用了临时表,哪个用户请求了最多的io,哪个线程占用了最多的内存,哪些索引是无用索引等
sys schema中包含了大量的视图,那么,这些视图的信息来自哪里呢?视图中的信息均来自performance schema统计信息。 这里 有一个很好的比喻:
For Linux users I like to compare performance_schema to /proc, and SYS to vmstat.
也就是说,performance schema提供了信息源,但是,没有很好的将这些信息组织成有用的信息,从而没有很好的发挥它们的作用。而sys schema使用performance schema信息,通过视图的方式给出解决实际问题的答案。
例如,下面这些问题,在MySQL 5.7之前,需要借助外部工具才能知道,在MySQL 5.7中,直接查询sys库下相应的表就能得到答案:
如何查看数据库中的冗余索引select * from sys.schema_redundant_indexes;
如何获取未使用的索引select * from schema_unused_indexes;
如何查看使用全表扫描的SQL语句select * from statements_with_full_table_scans 2.4 可用性
MySQL 5.7在可用性方面的改进也带给人不少惊喜。这里介绍特别有用的几项改进,包括:
在线设置 复制的过滤规则 不再需要重启MySQL,只需要停止SQL thread,修改完成以后,启动SQL thread
在线修改buffer pool的大小
MySQL 5.7为了支持online buffer pool resize,引入chunk的概念,每个chunk默认是128M,当我们在线修改buffer pool的时候,以chunk为单位进行增长或收缩。这个参数的引入,对innodb_buffer_pool_size的配置有了一定的影响。innodb要求buffer pool> Online DDL MySQL 5.7支持重命名索引和修改varchar的大小,这两项操作在之前的版本中,都需要重建索引或表