CentOS 安装mysql 5.7
方式一、rpm 安装包
1.安装 mysql 源
在 https://dev.mysql.com/downloads/repo/yum/ 找到 yum 源 rpm 安装包
#安装wget
yum -y install wget
# 下载
shell> wget https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
# 安装 mysql 源
shell> yum localinstall mysql57-community-release-el7-11.noarch.rpm
#检查 mysql 源是否安装成功
shell> yum repolist enabled | grep "mysql.*-community.*"
2.安装 MySQL
shell> yum install -y mysql-community-server
shell> systemctl start mysqld
#查看 MySQL 状态
shell> systemctl status mysqld
3.设置开机启动
shell> systemctl enable mysqld
# 重载所有修改过的配置文件
shell> systemctl daemon-reload
4.修改 root 本地账户密码
默认密码在 /var/log/mysqld.log
文件中
shell> grep 'temporary password' /var/log/mysqld.log
修改密码
shell> mysql -uroot -p
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'Toner123!';
或者
mysql> set password for 'root'@'localhost'=password('Toner123!');
以后通过 update set 语句修改密码
mysql> use mysql;
mysql> update user set password=PASSWORD('Toner123!') where user='root';
mysql> flush privileges;
5.添加远程登录用户
mysql> GRANT ALL PRIVILEGES ON *.* TO 'toner'@'%' IDENTIFIED BY 'Toner123!' WITH GRANT OPTION;
6.设置默认编码为 utf8
修改 /etc/my.cnf
配置文件
[mysqld]
character-set-server=utf8
[client]
default-character-set=utf8
[mysql]
default-character-set=utf8
#重启mysql
附录
默认配置文件路径:
配置文件:/etc/my.cnf
日志文件:/var/log/var/log/mysqld.log
服务启动脚本:/usr/lib/systemd/system/mysqld.service
socket文件:/var/run/mysqld/mysqld.pid