centos7安装mysql
1. 环境准备
CentOS-7 安装好,最好是Minimal版本的
新建soft目录,上传mysql-5.6.10-linux-glibc2.5-x86_64.tar.gz
配置好网络
2. 依赖安装
Mysql 编译安装需要使用perl,先把这些编译工具安装好
yum -y install perl
yum -y install perl-devel
yum -y install ‘perl(Data::Dumper)‘
3. 安装mysql
3.1. 解压
tar -zxvf mysql-5.6.10-linux-glibc2.5-x86_64.tar.gz
重命名
mv mysql-5.6.10-linux-glibc2.5-x86_64 mysql
把mysql里面的所有放置到 /usr/local/mysql下
mkdir /usr/local/mysql
mv * /usr/local/mysql
3.2. 初始化安装
3.2.1. 创建好数据目录
mkdir -p /data/mysql
3.2.2. 初始化
cd /usr/local/mysql/scripts
./mysql_install_db --user=root --basedir=/usr/local/mysql --datadir=/data/mysql --pid-file=/data/mysql/mysql.pid --tmpdir=/tmp --explicit_defaults_for_timestamp=true
3.2.3. 配置my.cnf文件
cd /usr/local/mysql/support-files
cp my-default.cnf /etc/my.cnf
cp mysql.server /etc/init.d/mysql
vi /etc/my.cnf
basedir = /usr/local/mysql
datadir = /data/mysql
socket = /tmp/mysql.sock
log-error = /data/mysql/error.log
pid-file = /data/mysql/mysql.pid
user = root
tmpdir = /tmp
3.2.4. 修改环境变量
vi /etc/profile
export MYSQL_HOME=/usr/local/mysql
export PATH=$MYSQL_HOME/bin:$PATH
source /etc/profile
3.2.5. 启动mysql
service mysql start
3.2.6. 登陆mysql,修改给root密码
mysql
mysql>use mysql;
mysql>update user set password=password(‘root‘) where user=‘root‘ and host=‘localhost‘;
mysql>flush privileges;
3.2.7. 允许远程访问
GRANT ALL PRIVILEGES ON *.* TO ‘root‘@‘%‘ IDENTIFIED BY ‘root‘ WITH GRANT OPTION;
flush privileges;
3.2.8. 关闭防火墙
systemctl stop firewalld.service
systemctl disable firewalld.service