Home  >  Article  >  Operation and Maintenance  >  How to install mysql5.7 on Centos

How to install mysql5.7 on Centos

藏色散人
藏色散人forward
2021-06-30 17:11:502788browse

1. Download 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. Unzip mysql and change the name

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. Add users and groups

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

4. Installation command

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. Modify the configuration file

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

6. Start, modify the root password, and add remote connection user permissions

#修改环境变量配置文件
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;

The above is the detailed content of How to install mysql5.7 on Centos. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:segmentfault.com. If there is any infringement, please contact admin@php.cn delete