- A+
所属分类:linux技术
CentOS7 安装MYSQL5.7 [详细过程]
YUM 安装
1.从mysql官网获取 yum 仓库
[root@stone tmp]# wget 'https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm'
2.安装yum repo
[root@stone tmp]# rpm -ivh mysql57-community-release-el7-11.noarch.rpm 警告:mysql57-community-release-el7-11.noarch.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY 准备中... ################################# [100%] 正在升级/安装... 1:mysql57-community-release-el7-11 ################################# [100%]
3.安装mysql
[root@stone tmp]# yum install -y mysql-community-server
4.如果安装过程中出现如下错误
源 "MySQL 5.7 Community Server" 的 GPG 密钥已安装,但是不适用于此软件包。请检查源的公钥 URL 是否配置正确。
使用如下命令 [root@stone rpm-gpg]# rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
5.启动mysql
[root@stone rpm-gpg]# systemctl start mysqld.service
6.查看运行状态
[root@stone rpm-gpg]# systemctl status mysqld.service ● mysqld.service - MySQL Server Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled) Active: active (running) since 日 2022-05-01 00:00:35 CST; 30s ago Docs: man:mysqld(8) http://dev.mysql.com/doc/refman/en/using-systemd.html Process: 2067 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS) Process: 2018 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS) Main PID: 2070 (mysqld) CGroup: /system.slice/mysqld.service └─2070 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid 5月 01 00:00:32 stone systemd[1]: Starting MySQL Server... 5月 01 00:00:35 stone systemd[1]: Started MySQL Server.
7.登录数据库
第一次启动的密码在日志中查找 [root@stone rpm-gpg]# cat /var/log/mysqld.log | grep password 2022-04-30T16:00:33.315107Z 1 [Note] A temporary password is generated for root@localhost: ZpiMyUag.4wl [root@stone rpm-gpg]#
8.登录后修改密码,如果要是设置复杂密码可以直接使用如下命令 直接设置
mysql> SET PASSWORD = PASSWORD('your new password'); mysql> flush privileges;
- 如果要设置简单密码 则需要先使用如下命令 设置密码策略
mysql> set global validate_password_policy=0;#设置密码检查策略为0 mysql> set global validate_password_length=1;#设置密码的长度为1
10.授权用户登录权限
mysql> grant all privileges on *.* to root@"%" identified by "new passwd"; mysql> flush privileges;
11.如果忘记密码
1. 暂停服务 systemctl stop mysql.service 2. 修改/etc/my.cnf 添加 skip-grant-tables 配置项目 3. 重启mysql服务 4. mysql -uroot -p 进入数据库 5. update user set password = password ( 'new-password' ) where user = 'root'; 6. flush privileges;