以下过程均在root用户下操作
安装
wget http://repo.mysql.com/mysql57-community-release-el7-10.noarch.rpm
rpm -Uvh mysql57-community-release-el7-10.noarch.rpm
rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
yum install -y mysql-community-server
启动及检测状态
systemctl start mysqld.service
systemctl status mysqld.service
获得生成的临时密码
grep 'temporary password' /var/log/mysqld.log
然后通过临时密码登录,再修改密码
mysql -u root -p
通过临时密码登录后,先设置全局密码规则
set global validate_password_policy=0;
set global validate_password_length=1;
SHOW VARIABLES LIKE 'validate_password%';
修改密码
ALTER USER 'root'@'localhost' IDENTIFIED BY 'yourpassword';
授权其他机器远程登录
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'yourpassword' WITH GRANT OPTION;
FLUSH PRIVILEGES;
exit;
开机自启动
systemctl enable mysqld.service
systemctl daemon-reload
新建用户
CREATE USER 'centosuser'@'localhost' IDENTIFIED BY 'password';
授予所有表的权限
GRANT ALL PRIVILEGES ON *.* TO 'centosuser'@'localhost';
FLUSH PRIVILEGES;
查看所有用户
select * from mysql.user;
修改配置
先停止mysql服务
systemctl stop mysqld.service
修改储存路径
mkdir /data/mysql
修改MySQL 配置文件 /etc/my.cnf,将以下两行添加到 [mysqld] 部分:
datadir=/data/mysql
socket=/var/lib/mysql/mysql.sock
注意:如果 [mysqld] 部分中已经存在 datadir 或 socket 选项,请将其更改为 /data/mysql 和 /var/lib/mysql/mysql.sock。
重新启动服务
systemctl start mysqld.service
验证储存路径
mysql -u root -p -e "SHOW VARIABLES LIKE 'datadir';"
设置中文字体
修改MySQL 配置文件 /etc/my.cnf,修改 [mysqld] 部分或[mysql]部分:
[mysql]
default-character-set=utf8
[mysqld]
character_set_server=utf8
重新启动服务
systemctl start mysqld.service