1 下载并安装MySQL官方的 Yum Repository
wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
使用上面的命令下载了安装用的Yum Repository,然后就可以直接yum安装了
yum -y install mysql-community-server
安装MySQL服务器
yum -y install mysql-community-server
Downloading packages: Running transaction check Running transaction test Transaction test succeeded Running transaction Erasing : mysql57-community-release-el7-10.noarch 1/1 Verifying : mysql57-community-release-el7-10.noarch 1/1 Removed: mysql57-community-release.noarch 0:el7-10 Complete! 安装成功
注:
安装时出现下面报警
Importing GPG key 0x5072E1F5:
Userid : "MySQL Release Engineering <mysql-build@oss.oracle.com>"
Fingerprint: a4a9 4068 76fc bd3c 4567 70c8 8c71 8d3b 5072 e1f5
Package : mysql57-community-release-el7-10.noarch (@/mysql57-community-release-el7-10.noarch)
From : /etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
Public key for mysql-community-libs-5.7.44-1.el7.x86_64.rpm is not installed
Failing package is: mysql-community-libs-5.7.44-1.el7.x86_64
GPG Keys are configured as: file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
异常原因:
MySQL GPG密匙过期导致
解决方案
安装之前导入2022年秘钥
rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
重新安装
运维指令
systemctl enable mysqld.service # 开机自启动
systemctl status mysqld.service # 查看服务状态
systemctl start mysqld.service # 启动服务
systemctl stop mysqld.service # 停止服务
systemctl restart mysqld.service # 重启服务
2 Mysql数据库设置
启动MySQL
systemctl start mysqld.service
查看MySQL运行状态
systemctl status mysqld.service
通过如下命令可以在日志文件中找出密码:
grep "password" /var/log/mysqld.log
进入数据库:
mysql -uroot -p
输入初始密码,MySQL默认必须修改密码之后才能操作数据库:
mysql> set global validate_password_policy=0; #修改密码设置规范
Query OK, 0 rows affected (0.00 sec)
mysql> set global validate_password_length=1; #修改密码设置规范
Query OK, 0 rows affected (0.00 sec)
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'newpassword';
Query OK, 0 rows affected (0.00 sec)
此时还有一个问题,就是因为安装了Yum Repository,以后每次yum操作都会自动更新,需要把这个卸载掉:
yum -y remove mysql57-community-release-el7-10.noarch
创建新用户:
1.登录MySQL
mysql -u root -p
2.添加用户
create user "***"@"%" identified by "******";
3.查询确认一下
select user,host,authentication_string from user
4.mysql给用户赋予所有权限(包括远程连接)
GRANT ALL PRIVILEGES ON *.* TO "***"@"%" IDENTIFIED BY "******" WITH GRANT OPTION;