二进制和源码版本安装MySQL5.7.13,并简单介绍不同之处。
一、通用二进制部分
1.下载MySQL通用二进制软件包。
[[email protected] ~]# wget http://120.52.72.21/cdn.mysql.com/c3pr90ntc0td//Downloads/MySQL-5.7/mysql-5.7.13-linux-glibc2.5-x86_64.tar.gz
2.解压软件。
[[email protected] ~]# tar xf mysql-5.7.13-linux-glibc2.5-x86_64.tar.gz -C /usr/local/
[[email protected] ~]# cd /usr/local/ && mv mysql-5.7.13-linux-glibc2.5-x86_64/ mysql57
[[email protected] ~]# ln -sv /usr/local/mysql57/bin/* /usr/local/bin/
3.初始化数据库。
[[email protected] ~]# groupadd mysql
[[email protected] ~]# useradd -s /sbin/nologin -M -g mysql mysql
[[email protected] ~]# mkdir /dbdata/
[[email protected] ~]# mysql_install_db --basedir=/usr/local/mysql57 --datadir=/dbdata --user=mysql
①.此时密码会生成到/root/.mysql_secret文件中
[[email protected] ~]# cat /root/.mysql_secret
# Password set for user ‘[email protected]‘ at 2016-06-25 17:20:44
yCwKDn*.r_ay
②.在MySQL5.7.6以后初始化数据库使用mysqld --inititalize或者initialize-insecure。(一个生成root密码,一个不生成)
[[email protected] ~]# mysqld --inititalize --basedir=/usr/local/mysql57 --datadir=/dbdata --user=mysql
4.拷贝MySQL启动脚本以及配置文件。
[[email protected] ~]# mv /etc/my.cnf /etc/my.cnf.bak
[[email protected] ~]# cp /usr/local/mysql57/support-files/my-default.cnf /etc/my.cnf
[[email protected] ~]# cp /usr/local/mysql57/support-files/mysql.server /etc/init.d/mysql57
[[email protected] ~]# chmod +x /etc/init.d/mysql57
[[email protected] ~]# sed -i ‘/^basedir=/s;$;/usr/local/mysql57;‘ /etc/init.d/mysql57
[[email protected] ~]# sed -i ‘/^datadir=/s;$;/dbdata;‘ /etc/init.d/mysql57
5.启动MySQL57数据库,设置开机启动。
[[email protected] ~]# service mysql57 start
[[email protected] ~]# chkconfig --add mysql57 && chkconfig --level 35 mysql57 on
6.登陆数据库,修改root密码为:xkops。
①.方法一:
mysql> set password=password(‘xkops‘);
Query OK, 0 rows affected, 1 warning (0.02 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
②.方法二:
mysql> select user,host,authentication_string from mysql.user;
+-----------+-----------+---------------------------------------------------------------------+
| user | host | authentication_string |
+-----------+-----------+--------------------------------------------------------------------+
| root | localhost | *5E4D24E68984D0087C9CB26B4658E832450D27BB |
| mysql.sys | localhost | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE |
+-----------+-----------+--------------------------------------------------------------------+
2 rows in set (0.00 sec)
mysql> update mysql.user set authentication_string=password(‘xkops‘) where user=‘root‘ and host=‘localhost‘;
Query OK, 0 rows affected, 1 warning (0.01 sec)
Rows matched: 1 Changed: 0 Warnings: 1
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
*注释:在新的版本中密码字段更改为:authentication_string.
二、源码部分
1.下载软件包。
[[email protected] ~]# yum -y install gcc gcc-c++ make cmake ncurses-devel
[[email protected] ~]# wget http://cdn.mysql.com/Downloads/MySQL-5.7/mysql-5.7.13.tar.gz
2.configure配置。
[[email protected] ~]# tar xf mysql-5.7.13.tar.gz
[[email protected] ~]# cd mysql-5.7.13
[[email protected] mysql-5.7.13]# cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql57/ \
-DMYSQL_DATADIR=/dbdata\
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock \
-DMYSQL_TCP_PORT=3306 \
-DENABLED_LOCAL_INFILE=1 \
-DEXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DDOWNLOAD_BOOST=1 \
-DWITH_BOOST=$HOME/my_boost
*注释:如果cmake出错,执行如下操作,然后重新配置。
[[email protected] mysql-5.7.13]# make clean
[[email protected] mysql-5.7.13]# rm -rf CMakeCache.txt
3.编译&安装
[[email protected] mysql-5.7.13]# make -j 2 && make install
其他步骤参照二进制安装方式配置。