查看当前系统版本的详细信息
# cat /etc/redhat-release
CentOS Linux release 7.9.2009 (Core)
yum源下载
地址:https://dev.mysql.com/downloads/repo/yum/
下载地址:https://repo.mysql.com//mysql80-community-release-el7-3.noarch.rpm
下载完成后使用yum命令本地安装yum源
# yum localinstall mysql80-community-release-el7-3.noarch.rpm
# yum repolist enabled | grep "mysql.*-community.*"
mysql-connectors-community/x86_64 MySQL Connectors Community 95
mysql-tools-community/x86_64 MySQL Tools Community 84
mysql80-community/x86_64 MySQL 8.0 Community Server 82
安装MySQL
# yum install -y mysql-community-server
# systemctl start mysqld
修改默认数据存储路径
默认存储路径是/var/lib/mysql,修改成/data/mysql
systemclt stop mysqld.service
mkdir /data/mysql
cp -a -R /var/lib/mysql/* /data/mysql/
chown mysql:mysql /data/mysql/
chmod 750 /data/mysql/
vim /ect/my.cnf
#datadir=/var/lib/mysql
#socket=/var/lib/mysql/mysql.sock
datadir=/data/mysql
socket=/data/mysql/mysql.sock
systemctl start mysqld
# 用户登录。mysql -uroot -p 输入密码,提示错误。SQLSTATE[HY000] [2002] Can‘t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock‘
ln -s /data/mysql/mysql.sock /var/lib/mysql/mysql.sock
MySQL常用命令
systemctl start mysqld
systemctl status mysqld
/var/log/mysqld.log找到root默认密码(有日志生成情况下)
# grep ‘temporary password‘ /var/log/mysqld.log
修改密码
ALTER USER ‘root‘@‘localhost‘ IDENTIFIED WITH mysql_native_password BY ‘eSem?a?ap‘;
flush privileges;