编译安装mysql-5.7.17
1.打开官方网站下载最新的mysql-5.7.17源码包
注意:选择源码下载
2.在自定义目录保存 boost/mysql 或者mysql-boost
https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-boost-5.7.17.tar.gz
http://sourceforge.net/projects/boost/files/boost/1.59.0/boost_1_59_0.tar.gz
https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.17.tar.gz
3.安装依赖包及编译工具
yum install -y gcc gcc-c++ automake autoconf make cmake libtool yum install -y bison bison-devel ncurses ncurses-devel libaio-devel
4.创建mysql用户和组 先查看是否已经存在
cat /etc/passwd | grep mysqlcat /etc/group | grep mysql
没有创建则新建mysql用户以及用户组:
groupadd mysqluseradd -r -g mysql -s /bin/false mysql #创建不可登陆用户
5. 创建MySQL安装目录和数据目录
1 mkdir /usr/local/mysql2 mkdir /usr/local/mysql/data
6. 解压boost并移动目录到指定目录中,否则cmake会报错
tar -zxvf boost_1_59_0.tar.gzmv boost_1_59_0 /usr/local/boost
7.解压并预编译配置mysql
tar -zxvf mysql-5.7.17.tar.gz #解压缩 cmake \-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \ #安装目录-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \ #sock目录-DDEFAULT_CHARSET=utf8 \ #默认编码-DDEFAULT_COLLATION=utf8_general_ci \ #默认效验规则-DWITH_MYISAM_STORAGE_ENGINE=1 \ #激活myisame-DWITH_INNOBASE_STORAGE_ENGINE=1 \ #激活innodb-DWITH_MEMORY_STORAGE_ENGINE=1 \ #激活memory-DWITH_READLINE=1 \ #快捷键功能-DENABLED_LOCAL_INFILE=1 \ #允许导入数据-DMYSQL_DATADIR=/usr/local/mysql/data \ #数据目录-DMYSQL_USER=mysql \ #用户名-DMYSQL_TCP_PORT=3306 \ #端口-DWITH_BOOST=/usr/local/boost #增强插件
8.安装 耐心等待...
make && make install
9.安装完毕之后调整配置文件 如下
mv /etc/my.cnf /etc/my.cnf.bak cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf
并修改配置信息
[mysqld]basedir=/usr/local/mysqldatadir=/usr/local/mysql/datasocket=/usr/local/mysql/mysql.sockuser=mysqlsymbolic-links=0skip-grant-tables //跳过权限表时 添加该命令[mysqld_safe]log-error=/usr/local/mysql/logs/mysqld.logpid-file=/usr/local/mysql/mysqld.pid
创建logs目录
mkdir /usr/local/mysql/logs touch /usr/local/mysql/logs/mysqld.log
10.修改mysql目录所有者
chown -R mysql:mysql /usr/local/mysql
11.初始化数据库
bin/mysqld \ --initialize --user=mysql \ --basedir=/usr/local/mysql \ --datadir=/usr/local/mysql/data
命令参数解释:
--initialize : 初始化随机密码,注意,初始化的密码是一个过期密码,登录后需要修改密码
--user: 指定账户
上一个命令执行完之后,会在命令提示符的最后给出随机密码,一定记住 将此密码记录下来
注: 之前版本mysql_install_db是在mysql_basedir/script下,
5.7放在了mysql_install_db/bin目录下,且已被废弃。
“–initialize” 会生成一个随机密码(~/.mysql_secret),“–initialize-insecure” 不会生成密码
–datadir目标目录下不能有数据文件shell> chown -R root * //保护mysql根目录
shell> chown -R mysql data
12. 添加MySQL服务
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld chmod 755 /etc/init.d/mysqld
13. 启动MySQL
service mysqld start
显示启动成功:Starting MySQL....... SUCCESS!
14 链接MySQL
/usr/local/mysql/bin/mysql -uroot -p
安装完mysql 之后,登陆以后,不管运行任何命令,总是提示重置密码
step 1: SET PASSWORD = PASSWORD('your new password');step 2: ALTER USER 'root'@'localhost' PASSWORD EXPIRE NEVER;step 3: flush privileges;
完成以上三步退出再登,使用新设置的密码就行了,以上除了红色的自己修改成新密码外,其他原样输入即可
15设为开机自动启动
chkconfig --add mysqld chkconfig mysqld on chkconfig --list mysqld #查看启动项
16添加mysql的环境变量
将MySQL编译生成的bin目录添加到当前Linux系统的环境变量中
echo -e ‘\nexport PATH=/usr/local/mysql/bin:$PATH\n’ >> /etc/profile && source /etc/profile
【mysql-boost-5.7安装(包含boost包的安装方式)】
1.安装依赖
yum install -y gcc gcc-c++ automake autoconf make cmake libtoolyum install -y bison bison-devel ncurses ncurses-devel libaio-devel
2.解压mysql
tar -zxvf mysql-boost-5.7.11.tar.gz
3.创建用户和组
groupadd mysqluseradd -r -g mysql -s /bin/false mysql
4.编译mysql
cd /tar/mysql-5.7.11/cmake \-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \-DDEFAULT_CHARSET=utf8 \-DDEFAULT_COLLATION=utf8_general_ci \-DWITH_BOOST=boostmake && make install
5.备份原有配置文件
cp /etc/my.cnf /etc/my.cnf.bakrm -f /etc/my.cnf
6.修改mysql用户和组
cd /usr/local/mysqlchown -R mysql chgrp -R mysql
7.创建数据目录
mkdir -p /data/mysql/data/
8.初始化mysql 开启ssl
bin/mysqld \--initialize-insecure \--user=mysql \--basedir=/usr/local/mysql \--datadir=/data/mysql/data \ bin/mysql_ssl_rsa_setup \--user=mysql \--basedir=/usr/local/mysql \--datadir=/data/mysql/data
9拷贝配置文件 及启动
cp support-files/my-default.cnf /etc/my.cnfcp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld chmod 755 /etc/init.d/mysqld
10 设置环境变量
vi /etc/profile
# 在profile文件末尾增加两行
PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATHexport PATH
# 使PATH搜索路径立即生效:
source /etc/profile
12.配置
vi /etc/my.cnf#修改第19行(取消注释且修改为) datadir = /data/mysql/data/
13.启动
service mysql start