共计 5396 个字符,预计需要花费 14 分钟才能阅读完成。
导读 | MySQL 5.7 版本的发布,也就是说从现在开始 5.7 已经可以在生产环境中使用,有任何问题官方都将立刻修复。 |
原生支持 Systemd
更好的性能:对于多核 CPU、固态硬盘、锁有着更好的优化
更好的 InnoDB 存储引擎
更为健壮的复制功能:复制带来了数据完全不丢失的方案,传统金融客户也可以选择使用 MySQL 数据库。此外,GTID 在线平滑升级也变得可能
更好的优化器:优化器代码重构的意义将在这个版本及以后的版本中带来巨大的改进,Oracle 官方正在解决 MySQL 之前最大的难题
原生 JSON 类型的支持
更好的地理信息服务支持:InnoDB 原生支持地理位置类型,支持 GeoJSON,GeoHash 特性
新增 sys 库:以后这会是 DBA 访问最频繁的库
MySQL 5.7 已经作为数据库可选项添加到 OneinStack — lnmp 安装工具中
yum -y install make gcc-c++ cmake bison-devel ncurses-devel
源码包有两种版本:
mysql-5.7.11.tar.gz 不带 boost 库,需要自行下载。
mysql-boost-5.7.11.tar.gz 自带 boost 库,在解压后的根目录,推荐下载。
wget http://cdn.mysql.com/Downloads/MySQL-5.7/mysql-boost-5.7.11.tar.gz
curl -O http://cdn.mysql.com/Downloads/MySQL-5.7/mysql-boost-5.7.11.tar.gz
tar -zxf mysql-boost-5.7.11.tar.gz
cd mysql-5.7.11
生成 makefile
cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DSYSCONFDIR=/etc \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DMYSQL_TCP_PORT=3306 \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DEXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8 \ [字符集]
-DDEFAULT_COLLATION=utf8_general_ci \ [排序规则 必须有,不然初始化数据库困难]
-DDOWNLOAD_BOOST=1 \ [从 MySQL 5.7.5 开始 Boost 库是必需的]
-DWITH_BOOST=/root/mysql-5.7.11/boost \
-DWITH_SYSTEMD=1 [支持 Systemd]
加上 -DWITH_SYSTEMD= 1 可以使用 systemd 控制 mysql 服务,默认是不开启 systemd 的。
然后
make -j 2 && make install
mysql 将会安装到 /usr/local/mysql 路径
慢慢等……
groupadd mysql
useradd -g mysql -s /sbin/nologin mysql
chown -R mysql:mysql /usr/local/mysql
在 mysqld.service,把默认的 pid 文件指定到了 /var/run/mysqld/ 目录,而并没有事先建立该目录,因此要手动建立该目录并把权限赋给 mysql 用户。
mkdir -p /var/run/mysqld
chown mysql:mysql /var/run/mysqld
log : /var/log/mysqld.log
pid : /var/run/mysqld/mysqld.pid
sock : /tmp/mysql.sock
cp support-files/my-default.cnf /etc/my.cnf
mysql 5.7 默认将 mysqld.service (/usr/local/mysql/) 文件安装到了 mysql 安装目录下的 usr/lib/systemd/system/,将 mysqld.service 复制到 /usr/lib/systemd/system/ 目录下
[root@localhost]/usr/local/mysql#cp usr/lib/systemd/system/mysqld.service /usr/lib/systemd/system
— 编辑 /etc/profile 文件在最后添加如下两行 —
vim /etc/profile
PATH=/usr/local/mysql/bin:$PATH
export PATH
source /etc/profile
bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
bin/mysql_ssl_rsa_setup
出现下列内容,初始化成功
2016-02-22T03:56:27.254356Z 1 [Warning] root@localhost is created with an empty password ! Please consider switching off the –initialize-insecure option.
-–initialize 会生成一个随机密码 (保存在~/.mysql_secret),而 -–initialize-insecure 不会生成密码,在 MySQL 安全配置向导 mysql_secure_installation 设置密码时,可自由选择 mysql 密码等级。
-–datadir 目标目录下不能有数据文件。
之前版本初始化程序 mysql_install_db 是在 /usr/local/mysql/script 下,并会在将来被移除,转而使用 mysqld 替代 已被废弃 mysql5.7 放在了 /usr/local/mysql/bin 目录下。
systemctl start mysqld.service
systemctl status mysqld.service
运行 MySQL 安全配置向导 mysql_secure_installation 设置密码,mysql 服务启动后才可执行
a) 为 root 用户设置密码
b) 删除匿名账号
c) 取消 root 用户远程登录
d) 删除 test 库和对 test 库的访问权限
e) 刷新授权表使修改生效
[root@localhost mysql]# mysql_secure_installation
Securing the MySQL server deployment.
Connecting to MySQL using a blank password. [使用空密码连接到 MySQL]
VALIDATE PASSWORD PLUGIN can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD plugin?[VALIDATE 密码插件可以被用来测试密码
并提高安全性。你是否想设置 VALIDATE 密码插件?]
Press y|Y for Yes, any other key for No: y
There are three levels of password validation policy: [有三种级别的密码验证策略:]
LOW Length >= 8
MEDIUM Length >= 8, numeric, mixed case, and special characters
STRONG Length >= 8, numeric, mixed case, special characters and dictionary file
[最小长度 > = 8
中等长度 > = 8,数字,大小写混合和特殊字符
最长长度 > = 8,数字,混合大小写,特殊字符和字典文件 ]
Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 0 [请输入 0 = 低,1 = 中 2 = 强:0]
Please set the password for root here. [请在这里设置 root 用户的密码。]
New password: [新密码:]
Re-enter new password: [重新输入新密码:]
Estimated strength of the password: 25 [密码的估计强度:25]
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y [您是否希望继续与提供的密码(按 y | Y 表示是,因为没有任何其他键):Y?]
… Failed! Error: Your password does not satisfy the current policy requirements [… 失败!错误:您的密码不符合当前的要求]
New password:
Re-enter new password:
Estimated strength of the password: 50 [密码的估计强度:50]
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment. [默认情况下,MySQL 安装有一个匿名用户,
允许任何人登录到 MySQL.]
Remove anonymous users? (Press y|Y for Yes, any other key for No) : y [删除匿名用户?]
Success. [成功。]
Normally, root should only be allowed to connect from
‘localhost’. This ensures that someone cannot guess at
the root password from the network. [通常情况下,Root 只允许其进行 ’localhost'( 本地) 连接
。]
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : n [禁止远程 root 登录?]
… skipping. [… 跳过。]
By default, MySQL comes with a database named ‘test’ that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment. [默认情况下,MySQL 带有一个名为“测试”数据库, 任何人都可以访问。这也是仅用于测试,并且应该移动到生产之前被删除环境。]
Remove test database and access to it? (Press y|Y for Yes, any other key for No) : n [删除测试数据库和访问权限?]
… skipping. [… 跳过。]
Reloading the privilege tables will ensure that all changes
made so far will take effect immediately. [刷新授权表以确保所有的变化取得将立即生效。]
Reload privilege tables now? (Press y|Y for Yes, any other key for No) : [现在刷新授权表?]
… skipping.
All done! [全部完成!]
mysql -u root -p
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'password' WITH GRANT OPTION; 此处含有隐藏内容,需要正确输入密码后可见!
mysql>FLUSH PRIVILEGES; [刷新权限]