wget https://repo.mysql.com//mysql80-community-release-el7-1.noarch.rpm rpm -ivh mysql80-community-release-el7-1.noarch.rpm
yum install mysql-server
报错:
解决方法:第三方的镜像站中均已移除CentOS 8的源,Centos 8版本已停止更新相应依赖导致的,下载新的yum源即可搞定。
执行如下四条命令即可
mv /etc/yum.repos.d /etc/yum.repos.d.bak mkdir -p /etc/yum.repos.d wget https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo -O /etc/yum.repos.d/Centos-vault-8.5.2111.repo wget https://mirrors.aliyun.com/repo/epel-archive-8.repo -O /etc/yum.repos.d/epel-archive-8.repo
执行成功后,再执行 yum install mysql-server
systemctl start mysqld.service
mysql -u root
登录成功页面:
ALTER USER 'root'@'localhost' IDENTIFIED BY 'root密码';
create database jingshuicat_test;
create user 'jingshuicat_test'@'%' identified by '7tlBWtJ0lUyz';
grant all privileges on jingshuicat_test.* to 'jingshuicat_test'@'%';
表示给用户jingshuicat_test赋予 jingshuicat_test库所有表的权限
开放3306端口
firewall-cmd --permanent --zone=public --add-port=3306/tcp
显示如下提示,表示防火墙没开启
开启防火墙:
sudo systemctl start firewalld
开启成功后再执行上面的开放端口命令即可
service mysqld stopRedirecting to /bin/systemctl stop mysqld.service 新创建一个mysql的目录,并且将文件转换成为mysql:mysql权限:
mkdir /data/mysql # 在将数据文件拷贝至mysql目录下之后可能还需要刷新一下权限 chown -R mysql:mysql /data/mysql拷贝/var/lib/mysql数据文件内容到/data/mysql:
cp -R /var/lib/mysql /data/mysql cp -R /var/log/mysql/ /data/mysql/log重新授权:
chown -R mysql:mysql /data/mysql修改配置文件:
cd /etc/my.cnf.d vim mysql-server.conf
mysqld] #老的配置 #datadir=/var/lib/mysql #socket=/var/lib/mysql/mysql.sock #log-error=/var/log/mysql/mysqld.log #新的配置 datadir=/data/mysql/mysql socket=/data/mysql/mysql/mysql.sock log-error=/data/mysql/log/mysqld.log pid-file=/run/mysqld/mysqld.pid创建链接:
ln -s /data/mysql/mysql/mysql.sock /var/lib/mysql/mysql.sock重启mysql:
service mysqld start用root账号进去之后,可以查看数据文件目录和数据库默认编码:
mysql> select @@datadir; +--------------------+ | @@datadir | +--------------------+ | /data/mysql/mysql/ | +--------------------+ 1 row in set (0.00 sec