搭建 MYSQL
一、搭建 mysql 5.7.19
1、下载 mysql 相关软件拷到 linux 下并解压
下载 boost_1_59_0.tar.gz 和 mysql-5.7.19.tar.gz 安装包
下载链接:https://pan.baidu.com/s/1YxhBaeiFjo372BuqaK_YpQ 密码:ba8k
解压 boost_1_59_0.tar.gz 到 /usr/local/boot 自行建立 boot 文件夹
[root@centos-7 /]# tar -xf boost_1_59_0.tar.gz /usr/local/boot
解压 mysql-5.7.19.tar.gz 到 /mysql 自行建立 /mysql 文件夹
[root@centos-7 /]# mkdir /mysql
[root@centos-7 /]# cd /mysql
[root@centos-7 /]# tar -xf mysql-5.7.19.tar.gz
注意:(一定要有 8G 以上足够的内存空间,要不然无法安装)
[root@centos-7 /]# df -h
文件系统 容量 已用 可用 已用% 挂载点
/dev/sda2 20G 2.2G 17.9G 22% /
2、安装编译工具 gcc-c++ ; ncurses-devel ; cmake
yum源安装一定是 iso 本地源 否则编译器版本过高无法搭建环境
[root@centos-7 /]# yum -y install gcc-c++ ncurses-devel cmake
3、新建用户 mysql;修改 /mysql 所有者和所属组为 mysql
[root@centos-7 /]# useradd mysql -s /sbin/nologin
[root@centos-7 /]# chown mysql /mysql
[root@centos-7 /]# chgrp mysql /mysql
二、开始编译安装 (在 /mysql/mysql-5.7.19 进行)
1、在 mysql-5.7.19.tar.gz 生成的 mysql-5.7.19 目录下用 cmake 进行编译
[root@centos-7 /]# cd /mysql/mysql-5.7.19
[root@centos-7 mysql-5.7.19]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql57 -DMYSQL_DATADIR=/data/mysql -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DMYSQL_TCP_PORT=3306 -DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DMYSQL_USER=mysql -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DDOWNLOAD_BOOST=1 -DWITH_BOOST=/usr/local/boost
2、使用 make 正式开始编译(此过程很漫长,请耐心等待)
[root@centos-7 mysql-5.7.19]# make
3、使用 make install 编译安装(稍等片刻就好)
[root@centos-7 mysql-5.7.19]# make install
三、初始化数据库 (在 /mysql/mysql-5.7.19 进行)
初始化数据库, 确保 /mysql 目录是 mysql 可写的
[root@centos-7 mysql-5.7.19]# /usr/local/mysql57/bin/mysqld --defaults-file=/etc/my.cnf --initialize --user=mysql
命令参数解释:
--defaults-file : 指定MySQL配置文件路径
--initialize : 初始化随机密码,注意,初始化的密码是一个过期密码,登录后需要立刻修改密码
--user: 指定运行用户
四、启动 mysql 服务
[root@centos-7 mysql-5.7.19]# /usr/local/mysql57/support-files/mysql.server start
五、无密码登陆 mysql 服务
[root@centos-7 ~]# vim /etc/my.cnf
......
[mysqld]
skip-grant-tables #加在服务器标签,免密码登陆
重启数据库,进入数据库
[root@centos-7 ~]# /usr/local/mysql57/support-files/mysql.server restart
[root@centos-7 ~]# /usr/local/mysql57/bin/mysql -uroot
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 447
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>
严格按照上述步骤来安装是不会发生报错的,一定要注意内存是否充足,内存不够是安装过程中最大的问题。。。