安装
准备
环境:CentOS Linux release 7.7.1908 (Core)
MySQL yum: https://dev.mysql.com/downloads/repo/yum/
MySQL tar:https://downloads.mysql.com/archives/
yum 安装
添加yum 源并配置阿里云加速
wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
yum -y install mysql57-community-release-el7-10.noarch.rpm
阿里云加速
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
安装mysql
yum -y install mysql-community-server
systemctl start mysqld.service
systemctl enable mysqld.service
tar 包安装
添加独立用户
groupadd mysql
useradd -g mysql mysql
下载tar 包执行如下命令
tar -zxvf mysql-5.7.28-el7-x86_64.tar.gz -C /usr/local
cd /usr/local
mv mysql-5.7.28-el7-x86_64/ mysql
给mysql文件夹赋权
chown -R mysql:mysql mysql
建立独立的数据库目录并赋予mysql的权限
mkdir data
chown -R mysql:mysql data
使mysql用户启动数据库服务,初始化数据目录
su mysql
/usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
修改my.cnf文件
basedir=<数据库安装目录>
datadir=<数据目录>
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
chmod 755 /etc/init.d/mysqld
启动
/etc/init.d/mysqld start
修改root
mysql -uroot -p -S /usr/local/mysql/mysql.sock
alter user 'root'@'localhost' identified by 'root';
创建数据库
create database lucky;
create user 'lucky'@'%' identified by 'lucky';
GRANT ALL PRIVILEGES ON *.* TO 'lucky'@'%';
flush privileges;