Centos安装mysql5.7

为了方便快捷的搭建linux环境,于是有了这几篇文字

  1. CentOS使用yum安装jdk
  2. CentOS安装tomcat
  3. CentOS安装Nginx
  4. CentOS安装MySql5.6
  5. CentOS安装MySql5.7

1下载mysql

#进入local目录
cd /usr/local/
#下载mysql
wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz

2.解压mysql修改名称

tar -zxvf mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz
mv mysql-5.7.17-linux-glibc2.5-x86_64 mysql
mkdir data

3.添加用户和组

groupadd mysql
useradd -r -s /sbin/nologin -g mysql mysql -d /usr/local/mysql
chown -R mysql.mysql /usr/local/mysql/

4安装命令

yum -y install libaio-devel
./bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/
cp -a ./support-files/my-default.cnf /etc/my.cnf
cp -a ./support-files/mysql.server /etc/init.d/mysqld

5.修改配置文件

#打开配置目录
vi /etc/my.cnf
#增加目录配置
basedir=/usr/local/mysql/
datadir=/usr/local/mysql/data

6.启动,修改root密码,添加远程连接用户权限

#修改环境变量配置文件
vi /etc/profile
#增加mysql全局变量,使service mysqld start可以在任意位置使用
export PATH=$PATH:/usr/local/mysql/bin
#即时生效
source /etc/profile
#启动mysql
service mysqld start
#mysql刚安装完毕没有密码进入mysql命令行
mysql -uroot -p
#查询mysql用户
select User, Host, Password FROM mysql.user;
#修改root密码
update mysql.user set password=password('root') where User="root";
#为root添加远程权限
grant all privileges on *.* to 'root'@'%'identified by 'root' with grant option;
#刷新权限
flush privileges; 


    原文作者:恒不动
    原文地址: https://segmentfault.com/a/1190000020343864
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞