由于MySQL 5.7需要boost 1.59以及以上版本,所以还需要下载boost库
wget http://sourceforge.net/projects/boost/files/boost/1.59.0/boost_1_59_0.tar.gz
解压boost并copy到/usr/local/boost目录
tar zxvf boost_1_59_0.tar.gz
cp -r boost_1_59_0 /usr/local/boost
安装编译所需要的常用组件和依赖包
yum -y install gcc gcc-c++ ncurses ncurses-devel bison libgcrypt perl make cmake
创建mysql用户组和用户,用来运行mysql服务器,-g指定用户组,-r创建系统用户
groupadd mysql
useradd -r -g mysql -s /bin/false -M mysql
解压Mysql,进入mysql目录
tar xf mysql-boost-5.7.19.tar.gz
cd mysql-5.7.19/
新建mysql安装所需要的目录
mkdir -p /usr/local/mysql /usr/local/mysql/{data,logs,pids}
修改/usr/local/mysql 目录所有者权限
chown -R mysql:mysql /usr/local/mysql
使用cmake命令进行编译安装
cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/data -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DMYSQL_TCP_PORT=3306 -DMYSQL_USER=mysql -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DENABLE_DOWNLOADS=1 -DDOWNLOAD_BOOST=1 -DWITH_BOOST=/usr/local/boost
使用make 命令进行编译
make
安装
make install
将mysql添加到环境变量,修改/etc/profile文件,在文件末尾添加以下内容:
export PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH
更新配置文件
source /etc/profile
将mysql服务文件添加到/etc/init.d目录,并给执行权限
cp support-files/mysql.server /etc/init.d/mysqld
chmod a+x /etc/init.d/mysqld
将mysql加入开机自启动
chkconfig --add mysqld
chkconfig mysqld on
chkconfig --list | grep mysqld
修改/etc/my.cnf文件,编辑配置文件,如下:
[mysqld]
datadir=/usr/local/mysql/data
socket=/usr/local/mysql/mysql.sock
[mysqld_safe]
log-error=/usr/local/mysql/logs/mysqld.log
pid-file=/usr/local/mysql/pids/mysqld.pid
# 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
[client]
default-character-set=utf8
socket=/usr/local/mysql/mysql.sock
[mysql]
default-character-set=utf8
socket=/usr/local/mysql/mysql.sock
#
# include all files from the config directory
#
!includedir /etc/my.cnf.d
保存后退出
初始化数据库:
–initialize 参数表示默认生成一个安全的密码,-initialize-insecure表示不生成密码
mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
创建mysql日志文件和pid文件
touch /usr/local/mysql/logs/mysqld.log
touch /usr/local/mysql/pids/mysqld.pid
修改权限为mysql
chown mysql.mysql -R /usr/local/mysql/
启动mysql
systemctl start mysqld
查看Mysql运行状态
ps -ef | grep mysql
root 47022 1 0 17:05 ? 00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/usr/local/mysql/data --pid-file=/usr/local/mysql/data/localhost.localdomain.pid
mysql 47174 47022 3 17:05 ? 00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/usr/local/mysql/logs/mysqld.log --pid-file=/usr/local/mysql/data/localhost.localdomain.pid --socket=/usr/local/mysql/mysql.sock
root 47205 1625 0 17:05 pts/0 00:00:00 grep --color=auto mysql
进入数据库,查看用户表信息(看到以下几个数据库,就说明Mysql数据库初始化成功)
mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.19 Source distribution
Copyright (c) 2000, 2017, 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 databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)
mysql>
进入mysql库,查看表信息(mysql 5.7版本以下的mysql数据库已经没有password字段了,passowrd字段改成了authentication_string,查询时使用authentication_string字段就行)
mysql> select host,user,authentication_string from user;
+-----------+---------------+-------------------------------------------+
| host | user | authentication_string |
+-----------+---------------+-------------------------------------------+
| localhost | root | |
| localhost | mysql.session | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE |
| localhost | mysql.sys | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE |
+-----------+---------------+-------------------------------------------+
3 rows in set (0.00 sec)
mysql>
设置root用户密码
mysql> UPDATE user SET authentication_string=PASSWORD('newpassword') WHERE user='root';
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 1
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql>
END