centos7 源码方式安装MySQL5.6
1.上传MySQL源码包mysql-5.6.38.tar.gz到/opt
http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.22.tar.gz/from/http://cdn.mysql.com/
2.yum方式安装相关依赖包
# yum -y install cmake bison git ncurses-devel gcc gcc-c++
3.创建一个用户名为mysql的用户并加入mysql用户组
# groupadd mysql
# useradd -g mysql mysql
4.解压mysql-5.6.38.tar.gz,并且创建mysql安装目录和数据库文件存放目录
# tar zxvf mysql-5.6.38.tar.gz
# mkdir /usr/local/mysql
# mkdir /usr/local/mysql/data
# cd mysql-5.6.38/
# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DMYSQL_DATADIR=/usr/local/mysql/data -DMYSQL_TCP_PORT=3306 -DMYSQL_USER=mysql -DENABLE_DOWNLOADS=1
如果此过程出现error,则执行命令 # rm -rf /opt/mysql-5.6.38/CMakeCache.txt
安装相关依赖包,再重新 执行cmake
# make
# make install
安装完之后,清除临时文件
# make clean
修改目录属主权限
# chown -R mysql:mysql /usr/local/mysql/data/
# chown -R mysql:mysql /usr/local/mysql/
5.创建MySQL Server系统表
# cd /usr/local/mysql/
# scripts/mysql_install_db --user=mysql --datadir=/usr/local/mysql/data
此处出现报错
执行命令
# rpm -ivh /mnt/Packages/perl-Data-Dumper-2.145-3.el7.x86_64.rpm
然后再执行
# scripts/mysql_install_db --user=mysql --datadir=/usr/local/mysql/data
把初始化生成的 /usr/local/mysql/my.cnf 配置文件的属主数组更改为mysql
# chown -R mysql:mysql /usr/local/mysql
配置启动脚本
# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
启动MySQL
# /etc/init.d/mysql status
# /etc/init.d/mysql start
配置环境变量
# vi /etc/profile
在后面加上
PATH=$PATH:$HOME/bin:/usr/local/mysql/bin:/usr/local/mysql/lib
export PATH
变量生效
# source /etc/profile
设置数据库密码
# mysql -uroot -p
密码初始化为空
创建一个数据库用户,用于客户端访问
mysql> create user dev@'%' identified by '123456';
赋所有权限
mysql> grant all privileges on *.* to 'dev'@'%' identified by '123456';
6.根据需要设置开机自动启动服务
# chkconfig mysql on