详细的MySQL安装教程
文中MySQL版本为5.7.32
装置服务端
-
下载mysql server端的 rpm 文件
下载地址:https://downloads.mysql.com/archives/community/
挑选版本:mysql-community-server-5.7.32-1.el7.x86_64.rpm
- 上传至服务器 /app/soft
-
装置mysql所需求的组件
yum install libaio(可选)
-
装置mysql Server
rpm -ivh mysql-community-server-5.7.32-1.el7.x86_64.rpm --nodeps --force
假如不加--nodeps --force则提示需求装置客户端依赖等过错
warning: mysql-community-server-5.7.32-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY error: Failed dependencies: mysql-community-client(x86-64) >= 5.7.9 is needed by mysql-community-server-5.7.32-1.el7.x86_64 mysql-community-common(x86-64) = 5.7.32-1.el7 is needed by mysql-community-server-5.7.32-1.el7.x86_64
- 检查是否装置
[root-dev soft]# rpm -qa | grep mysql mysql-community-server-5.7.32-1.el7.x86_64
- 启动mysql并检查状况
[root-dev soft]# systemctl start mysqld.service -- 启动 [root-dev soft]# systemctl status mysqld.service -- 检查状况 ● mysqld.service - MySQL Server Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled) Active: active (running) since Mon 2021-01-18 11:32:17 CST; 15s ago Docs: man:mysqld(8) http://dev.mysql.com/doc/refman/en/using-systemd.html Process: 7054 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS) Process: 6825 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS) Main PID: 7057 (mysqld) CGroup: /system.slice/mysqld.service └─7057 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid
经过上面咱们就装置好了MySQL的Server端,这时候是无法运用MySQL指令登录的,还需求装置一个Client端才行!
装置客户端
-
下载mysql client端的 rpm 文件
下载地址:https://downloads.mysql.com/archives/community/
挑选版本:mysql-community-client-5.7.32-1.el7.x86_64.rpm
- 上传至服务器 /app/soft
-
装置客户端
rpm -ivh mysql-community-client-5.7.32-1.el7.x86_64.rpm --nodeps --force
同理,这里假如不加--nodeps --force指令还是会出现如下所示的过错
[root-dev soft]# rpm -ivh mysql-community-client-5.7.32-1.el7.x86_64.rpm warning: mysql-community-client-5.7.32-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY error: Failed dependencies: mysql-community-libs(x86-64) >= 5.7.9 is needed by mysql-community-client-5.7.32-1.el7.x86_64
装置完Server和Client端后,还需求修正一些默许装备。
装备
- 获取原始暗码
grep "password" /var/log/mysqld.log 2021-01-18T03:32:13.444809Z 1 [Note] A temporary password is generated for root : r8G>.aGR,GaA
-
运用原始暗码登录mysql服务器
mysql -uroot -p输入上面获取到的暗码回车登录
-
修正暗码
ALTER USER 'root'@'localhost' IDENTIFIED BY 'new password'
其间 ‘new password’ 替换成你要设置的暗码,留意:暗码设置必须要大小写字母数字和特别符号(,/';:等),不然不能装备成功。
3.1 修正暗码安全策略 假如出现如下过错则阐明新暗码不符合暗码策略
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
可经过指令SHOW VARIABLES LIKE 'validate_password%';检查安全策略
可经过指令修正对应的安全策略,如将暗码等级设置成LOW:set global validate_password_policy=LOW;如将暗码长度设置成8set global validate_password_length=6;
mysql 暗码策略相关参数:
1)validate_password_length 固定暗码的总长度; 2)validate_password_dictionary_file 指定暗码验证的文件途径; 3)validate_password_mixed_case_count 整个暗码中至少要包括大/小写字母的总个数; 4)validate_password_number_count 整个暗码中至少要包括阿拉伯数字的个数; 5)validate_password_policy 指定暗码的强度验证等级,默许为 MEDIUM; 6)validate_password_special_char_count 整个暗码中至少要包括特别字符的个数;关于 validate_password_policy 的取值:
LOW:只验证长度;
MEDIUM:验证长度、数字、大小写、特别字符;
STRONG:验证长度、数字、大小写、特别字符、字典文件;
1.新增远程登录用户
create user 'xxxxxx''%' identified by 'password'; GRANT ALL PRIVILEGES ON *.* TO 'xxxxxx''%' identified by password'; flush privileges;
-
修正mysql默许语言为utf8mb4
默许情况下MySQL运用的语言是latinl,可在登录mysql服务的情况下运用status指令检查,需求将其修正成干流的utf8mb4
先退出mysql,然后再到/etc目录下的my.cnf文件下新增以下内容(见红框)
vi /etc/my.cnf
修正完成后重启mysql
systemctl restart mysqld.service
重新登录mysql,再次检查状况:
经过上面几步,咱们现已能够运用MySQL进行开发测试了,可是此时的MySQL并不能直接用于出产,咱们还得修正MySQL服务器的装备参数,提升其性能与吞吐率。
我有话说: