Linux 之 CentOS 7安装MySQL5.7
Linux 之 CentOS 7安装MySQL5.7
1.下载MySQL yum 包
wget http://repo.mysql.com/mysql57-community-release-el7-10.noarch.rpm
2.安装MySQL源
rpm -Uvh mysql57-community-release-el7-10.noarch.rpm
3.安装MySQL服务端
yum install -y mysql-community-server
4.启动MySQL
systemctl start mysqld.service
5.检查是否启动成功
systemctl status mysqld.service
6.获取临时密码
mysql5.7为root用户随机生成了一个密码
grep 'temporary password' /var/log/mysqld.log
7.登录mysql,修改密码
mysql -uroot -p
8.修改密码
更改密码规则
mysql> set global validate_password_policy=0; mysql> set global validate_password_length=1;
设置密码
ALTER USER 'root'@'localhost' IDENTIFIED BY 'yourpassword';
9.开启远程连接
mysql> use mysql; #%代表所有连接 mysql> update user set Host = '%' where Host = 'localhost' and User='root'; #刷新权限表 mysql> flush privileges;
10.开启开机自启
一般默认自启
systemctl enable mysqld
systemctl daemon-reload
11.设置字符集
打开配置文件
vim /etc/my.cnf
改成如下
# For advice on how to change settings please see # http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html [mysql] default-character-set=utf8 [mysqld] datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock default-storage-engine=INNODB character_set_server=utf8 symbolic-links=0 log-error=/var/log/mysqld.log pid-file=/var/run/mysqld/mysqld.pid
重启mysql,使配置生效
service mysqld restart
12.放行3306端口
#放行3306端口 firewall-cmd --zone=public --add-port=3306/tcp --permanent #重启防火墙 firewall-cmd --reload
13.卸载mysql仓库
14.navicat连接测试
使用navicat创建数据库,创建表,添加数据。服务端测试查询