赞
踩
1、下载Mysql的Yum仓库
https://dev.mysql.com/downloads/repo/yum/
2、将第一步下载的文件拖进服务器,进行安装:
yum localinstall mysql80-community-release-el7-3.noarch.rpm
3、检测源是否安装成功
yum repolist enabled | grep "mysql.-community."
4、选择版本
vi /etc/yum.repos.d/mysql-community.repo
5、安装
yum install mysql-community-server
6、启动mysql
systemctl start mysqld
如果启动报如下错误错,则需要删除/var/lib目录下的mysql目录,是因为目标路径已经存在/var/lib/mysql /,导致无法初始化,删除完再次重启就行:
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Sat 2020-12-12 16:53:16 CST; 1min 48s ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Process: 18399 ExecStart=/usr/sbin/mysqld $MYSQLD_OPTS (code=exited, status=1/FAILURE)
Process: 18373 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
Main PID: 18399 (code=exited, status=1/FAILURE)
Status: "Server startup in progress"
Error: 2 (No such file or directory)
Dec 12 16:53:16 iZ2zebcdfzd6516iqs3di2Z mysqld[18399]: 2020-12-12T08:53:16.153655Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or e...re release.
Dec 12 16:53:16 iZ2zebcdfzd6516iqs3di2Z mysqld[18399]: 2020-12-12T08:53:16.155254Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.22) starting as process 18399
Dec 12 16:53:16 iZ2zebcdfzd6516iqs3di2Z mysqld[18399]: 2020-12-12T08:53:16.167524Z 1 [ERROR] [MY-011011] [Server] Failed to find valid data directory.
Dec 12 16:53:16 iZ2zebcdfzd6516iqs3di2Z mysqld[18399]: 2020-12-12T08:53:16.167640Z 0 [ERROR] [MY-010020] [Server] Data Dictionary initialization failed.
Dec 12 16:53:16 iZ2zebcdfzd6516iqs3di2Z mysqld[18399]: 2020-12-12T08:53:16.167694Z 0 [ERROR] [MY-010119] [Server] Aborting
Dec 12 16:53:16 iZ2zebcdfzd6516iqs3di2Z mysqld[18399]: 2020-12-12T08:53:16.168284Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.22) MySQL C...rver - GPL.
Dec 12 16:53:16 iZ2zebcdfzd6516iqs3di2Z systemd[1]: mysqld.service: main process exited, code=exited, status=1/FAILURE
Dec 12 16:53:16 iZ2zebcdfzd6516iqs3di2Z systemd[1]: Failed to start MySQL Server.
Dec 12 16:53:16 iZ2zebcdfzd6516iqs3di2Z systemd[1]: Unit mysqld.service entered failed state.
Dec 12 16:53:16 iZ2zebcdfzd6516iqs3di2Z systemd[1]: mysqld.service failed.
Hint: Some lines were ellipsized, use -l to show in full.
7、设置开机自启动
systemctl enable mysqld
systemctl daemon-reload
8、设置mysql密码:
网上说的在/var/log/mysqld.log、/var/log/mysql.log中有密码,但进去后里面啥都没有。
所以通过修改mysql配置文件,让他跳过密码使用root进入数据库
①找到/etc/my.cnf,编辑:vim /etc/my.cnf
②在[mysqld]标签下或者文件最下面添加一句skip-grant-tables
③esc退出编辑,然后输入 :wq保存退出 ,然后重启服务器 service mysqld restart 让修改生效
④mysql -u root 就可以直接进入数据库了。
⑤然后是修改密码,最好设置密码复杂点,建议:大写字母+小写字母+符号。否则后面mysql会报错让你改到符合mysql的安全策略,或者也可以修改mysql安全策略
mysql> USE mysql;
可用命令查看 validate_password 密码验证插件是否安装: mysql> SHOW VARIABLES LIKE 'validate_password%';
MySQL 8.0 调整密码验证规则:
mysql> set global validate_password.policy=0;
mysql> set global validate_password.length=1;
方案一:限制本地登录
ALTER USER 'root'@'localhost' IDENTIFIED BY '新密码';
flush privileges;
方案二:可以任意IP与第三方客户端登录
- ALTER USER 'root'@'localhost' IDENTIFIED BY '密码' PASSWORD EXPIRE NEVER; #修改root的密码与加密方式
- use mysql; #切换到mysql库
- update user set host='%' where user = 'root'; #更改可以登录的IP为任意IP
- flush privileges; #刷新权限
- ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '密码'; #再次更改root用户密码,使其可以在任意IP访问
- flush privileges; #刷新权限
mysql> quit
⑥改完密码,再将配置文件改回来,就把添加的那句删掉就好了,然后再次重启服务器service mysqld restart
⑦然后就可以使用 mysql -uroot -p输入你的新密码进入啦
问题总结: 通过查看 MySQL5.7 和 MySQL8.0 密码验证插件对比,可知两个版本中,变量名不一样。(*_password_policy 和 *_password.policy )。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。