CentOS7 yum安装mysql

下载mysql源安装包

 wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm 

安装mysql源

yum localinstall mysql57-community-release-el7-8.noarch.rpm  

检查mysql源是否安装成功

yum repolist enabled | grep "mysql.*-community.*"

修改yum源 【可跳过】

vim /etc/yum.repos.d/mysql-community.repo

改变默认安装的mysql版本。比如要安装5.6版本,将5.7源的enabled=1改成enabled=0。然后再将5.6源的enabled=0改成enabled=1即可。

enabled=1表示即将要安装的mysql版本,这个文件也可以不修改,默认安装mysql最高版本

安装MySQL

yum install mysql-community-server 

启动MySQL服务并设置开机启动

systemctl start mysqld
systemctl enable mysqld
systemctl daemon-reload
1、这里如果报错:Failed to start mysqld.service Unit not found  

步骤 1:先检查mysqld服务的systemd配置文件是否存在
ls /usr/lib/systemd/system/mysqld.service
如果文件存在,将输出文件路径;如果文件不存在,则需要执行下一步操作。

步骤 2:重新安装MySQL服务器
yum install mysql-server

步骤 3:再次执行:
systemctl start mysqld
2、这里如果报错:The GPG keys listed for the "MySQL 5.7 Community Server" repository are already installed but they are not correct for this package. Check that the correct key URLs are configured for this repository.

运行:rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022

端口开放

firewall-cmd --zone=public --add-port=3306/tcp --permanent
firewall-cmd --reload

修改root本地登录密码

查看mysql密码
grep 'temporary password' /var/log/mysqld.log

连接mysql
mysql -uroot -p

修改密码【注意:后面的分号一定要跟上】
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'newPass123~!';
或者:
mysql> set password for 'root'@'localhost'=password('newPass123~!'); 

查看当前的密码策略
mysql> show variables like '%password%';

添加远程登录用户

mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'youpassword' WITH GRANT OPTION; 

以上步骤就已经安装好了Mysql并且可以使用了,其他相关内容:

启动:service mysqld start 
关闭:service mysqld stop
重启:service mysqld restart
查看服务状态:service mysqld status
查看MySql系统配置:cat /etc/my.cnf

解决报错:mysql 遇见 Expression #1 of SELECT list is not in GROUP BY clause and … 的问题

select @@global.sql_mode;
set @@global.sql_mode = 'STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';

猜你喜欢

1 Response

发表评论

最新发布