安装前工作:
1,从官方网址下载MySQL5.7.11源码包,大概49M
2,安装好CentOS6.5 64位操作系统。建议update操作系统,以便是此版本最新的
3. yum -y install gcc gcc-c++ autoconf automake zlib* fiex* libxml* ncurses-devel libmcrypt* libtool-ltdl-devel* make cmake libaio libaio-devel autoconf bzr bison libtool make cmake gcc-c++ bison ncurses-devel //这是个人在安装老版本使用的,相关依赖包
软件放在/data
正式安装MySQL
1. 添加MySQL用户和所属组
groupadd mysql
useradd -r -g mysql mysql
2. 解压源码包
mkdir /data
chmod 755 /data
cd /data
wget http://mirrors.sohu.com/mysql/MySQL-5.7/mysql-5.7.11.tar.gz
tar -zxvf mysql-5.7.11.tar.gz
3. 开始踩MySQL的坑
设置好make编译的目录
cd mysql-5.7.11
cmake \
-DCMAKE_INSTALL_PREFIX=/data/mysql \ // 安装根目录
-DMYSQL_DATADIR=/mysql/data \ //数据库存储路径
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock \ //这个最好换成 /data 下
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DEXTRA_CHARSETS=all \
-DENABLED_LOCAL_INFILE=1 \
-DDOWNLOAD_BOOST=1 \
-DWITH_BOOST=/data/boost_1_59_0 //需要boost支持,这一点跟5.6版本的不一样
-- Configuring done
-- Generating done
-- Build files have been written to: /root/mysql-5.7.11
到这里cmake完成,比较顺利
cmake -DCMAKE_INSTALL_PREFIX=/data/mysql -DMYSQL_DATADIR=/mysql/data -DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSETS=all -DENABLED_LOCAL_INFILE=1 -DDOWNLOAD_BOOST=1 -DWITH_BOOST=/data/boost_1_59_0
5. make 操作
# make //漫长的过程 主要看机器的配置
Linking CXX executable my_safe_process
[100%] Built target my_safe_process
注意:
mysql 5.6.19 版本编译后的文件包约2G // 笔者一直使用的是5.6.19及以上版本
MySQL5.7.11 编译安装对磁盘的需求也比以往的版本多很多,make之后的 mysql-5.7.11 文件夹约4.8G
开始编译前:
# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root 27G 4.5G 21G 19% /
tmpfs 996M 228K 996M 1% /dev/shm
/dev/sda1 485M 39M 421M 9% /boot
编译完成后:
# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root 27G 9.5G 16G 38% /
tmpfs 996M 228K 996M 1% /dev/shm
/dev/sda1 485M 39M 421M 9% /boot
此时如果执行make install 会因为磁盘不足,导致缺失重要的文件,笔者,尝试过几次,均失败。 最后的报错如下:
-- Installing: /usr/local/mysql/bin/mysql_embedded
CMake Error at libmysqld/examples/cmake_installNaNake:42 (FILE):
file INSTALL cannot copy file
"/root/mysql-5.7.11/libmysqld/examples/mysql_embedded" to
"/usr/local/mysql/bin/mysql_embedded".
Call Stack (most recent call first):
cmake_installNaNake:116 (INCLUDE)
make: *** [install] Error 1
并且5.7.11的安装文件也比以往略大
5.6.19 ---->1.1G
5.7.11 ---->1.9G
所以建议大家尽量给多一点空间
6. make install 安装:
# make install 从最后一行看到密码?
........
-- Installing: /usr/local/mysql/support-files/magic
-- Installing: /usr/local/mysql/share/aclocal/mysql.m4
-- Installing: /usr/local/mysql/support-files/mysql.server
7. 初始化MySQL
cd /data/mysql/bin
# ./mysqld --initialize --user=mysql --datadir=/data/mysql/data --basedir=/data/mysql --socket=/tmp/mysql.sock //在MySQL 5.7.6版本以前是 bin/mysql_install_db --user
2016-02-25T04:36:27.941245Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2016-02-25T04:36:29.363359Z 0 [Warning] InnoDB: New log files created, LSN=45790
2016-02-25T04:36:29.529261Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2016-02-25T04:36:29.615486Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 56a9ad19-db79-11e5-bc10-080027207e2e.
2016-02-25T04:36:29.635578Z 0 [Warning] Gtid table is not ready to be used. Table ‘mysql.gtid_executed‘ cannot be opened.
2016-02-25T04:36:29.645190Z 1 [Note] A temporary password is generated for [email protected]: oej<ibtee2r?
8. 添加MySQL服务
cd /data/mysql-5.7.11/support-files
# cp mysql.server /etc/init.d/mysqld
cd /etc/init.d/
chmod +x mysqld
chmod a+wrx /tmp //给socket 存储文件 写的权限
9. 编辑my.cnf文件
# vi /etc/my.cnf //添加下面的,这里为了简洁,省去其他的,都是按照默认的 注释掉以前的
[mysqld]
port=3306
basedir=/data/mysql
datadir=/data/mysql/data
socket=/tmp/mysql.sock
[mysqld]
port=3306
basedir=/data/mysql
datadir=/data/mysql/data
socket=/tmp/mysql.sock
init_connect=‘set autocommit=0‘
#datadir=/var/lib/mysql
#socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
#symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd
[mysqld_safe]
log-error=/var/log/mariadb/mariadb.log
pid-file=/var/run/mariadb/mariadb.pid
#
# include all files from the config directory
#
10. 重启MySQL
chown mysql.mysql /data/mysql/
# /etc/init.d/mysqld restart
Starting MySQL.. SUCCESS!
chkconfig mysqld on
如果有报错可以删除/data/mysql/data下的
ib_logfile1 ib_logfile0
rm ib_logfile0
Y
再次启动
ps -ef|grep mysqld
11. 登录MySQL
# cd /data/mysql/bin
# ./mysql -uroot -p //第一次登录MySQL,密码文件在,也可以从make install 最后的一行看到密码
Enter password:
这边忘记mysql的密码了 方法:
vi /etc/my.cnf #编辑文件,找到[mysqld],在下面添加一行skip-grant-tables
[mysqld]
skip-grant-tables
:wq! #保存退出
service mysqld restart #重启MySQL服务
cd /data/mysql/bin
./mysql -u root -p #直接按回车,这时不需要输入root密码。
use mysql
update user set authentication_string=PASSWORD(‘123456‘) where User=‘root‘;
flush privileges; #刷新系统授权表
grant all on *.* to ‘root‘@‘localhost‘ identified by ‘123456‘ with grant option;
vi /etc/my.cnf 编辑文件,找到[mysqld],删除skip-grant-tables这一行
:wq! #保存退出
service mysqld restart #重启mysql,这个时候mysql的root密码已经修改为123456
mysql -uroot -p #进入mysql控制台
123456 #输入密码
mysql> show warnings;
+---------+------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Level | Code | Message //下面提示我那种方法以后将会被遗弃 |
+---------+------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Warning | 1287 | ‘SET PASSWORD = PASSWORD(‘‘)‘ is deprecated and will be removed in a future release. Please use SET PASSWORD = ‘‘ instead |
+---------+------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
结束!