centos7使用yum方式安装mysql
wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
#安装mysql源
yum localinstall mysql57-community-release-el7-8.noarch.rpm
查看是否安装成功
yum repolist enabled | grep "mysql.*-community.*"
如下结果代码已经安装源
[root@localhost conf]# yum repolist enabled | grep "mysql.*-community.*"
mysql-connectors-community/x86_64 MySQL Connectors Community 221
mysql-tools-community/x86_64 MySQL Tools Community 135
mysql57-community/x86_64 MySQL 5.7 Community Server 544
#安装mysql
yum install -y mysql-community-server
启动mysql:
#启动mysql
systemctl start mysqld
#查看mysql启动状态
systemctl status mysqld
#重启mysql
systemctl restart mysqld
#停止mysql
systemctl stop mysqld
设置开机启动:
#设置开机启动(已亲测)
shell> systemctl enable mysqld
shell> systemctl daemon-reload
通过日志查询首次生成的默认
#查看初始化
grep 'temporary password' /var/log/mysqld.log
红框代表默认的:
登录,并修改:
mysql -uroot -p
#修改
ALTER USER 'root'@'localhost' IDENTIFIED BY 'Root123456!';
一般而言为了安全,会创建一个用户来操作数据库:
#为了安全,创建一个用户
mysql> GRANT ALL PRIVILEGES ON *.* TO 'dbroot'@'%' IDENTIFIED BY 'Root123456!' WITH GRANT OPTION;
配置文件:/etc/my.cnf
日志文件:/var/log/mysqld.log
服务启动脚本:/usr/lib/systemd/system/mysqld.service
socket文件:/var/run/mysqld/mysqld.pid
如果防火墙开启着,则可能无法访问数据库,需要检查防火墙是否拦截。
#查看防火墙状态
firewall-cmd --state
#永久放开3306端口
firewall-cmd --zone=public --add-port=3306/tcp --permanent
#重新加载防火墙
firewall-cmd --reload