centos7下mysql5.7的安装
Posted jenkins
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了centos7下mysql5.7的安装相关的知识,希望对你有一定的参考价值。
1.通过yum repository安装,地址https://dev.mysql.com/downloads/repo/yum/
2.下载rpm文件
wget https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
3.可以参考https://dev.mysql.com/doc/mysql-yum-repo-quick-guide/en/安装mysql5.7
4.Adding the MySQL Yum Repository
rpm -Uvh mysql80-community-release-el7-3.noarch.rpm
[root@iZbp1gg50ddqbgxf1jpqwwZ home]# rpm -Uvh mysql80-community-release-el7-3.noarch.rpm
warning: mysql80-community-release-el7-3.noarch.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:mysql80-community-release-el7-3 ################################# [100%]
5.查看现在mysql版本
[root@iZbp1gg50ddqbgxf1jpqwwZ home]# [root@iZbp1gg50ddqbgxf1jpqwwZ home]# yum repolist all | grep mysql
mysql-cluster-7.5-community/x86_64 MySQL Cluster 7.5 Community disabled
mysql-cluster-7.5-community-source MySQL Cluster 7.5 Community - disabled
mysql-cluster-7.6-community/x86_64 MySQL Cluster 7.6 Community disabled
mysql-cluster-7.6-community-source MySQL Cluster 7.6 Community - disabled
mysql-cluster-8.0-community/x86_64 MySQL Cluster 8.0 Community disabled
mysql-cluster-8.0-community-source MySQL Cluster 8.0 Community - disabled
mysql-connectors-community/x86_64 MySQL Connectors Community enabled: 42
mysql-connectors-community-source MySQL Connectors Community - disabled
mysql-tools-community/x86_64 MySQL Tools Community enabled: 19
mysql-tools-community-source MySQL Tools Community - Sourc disabled
mysql-tools-preview/x86_64 MySQL Tools Preview disabled
mysql-tools-preview-source MySQL Tools Preview - Source disabled
mysql55-community/x86_64 MySQL 5.5 Community Server disabled
mysql55-community-source MySQL 5.5 Community Server - disabled
mysql56-community/x86_64 MySQL 5.6 Community Server disabled
mysql56-community-source MySQL 5.6 Community Server - disabled
mysql57-community/x86_64 MySQL 5.7 Community Server disabled
mysql57-community-source MySQL 5.7 Community Server - disabled
mysql80-community/x86_64 MySQL 8.0 Community Server enabled: 49
mysql80-community-source MySQL 8.0 Community Server - disabled
6.选择自己所需的版本,如5.7
yum-config-manager --disable mysql80-community
yum-config-manager --enable mysql57-community
7.如果没有yum-config-manager指令
yum -y install yum-utils
8.查看现在启用的mysql版本
[root@iZbp1gg50ddqbgxf1jpqwwZ home]# yum repolist all | grep mysql
Not using downloaded mysql-connectors-community/repomd.xml because it is older than what we have:
Current : Fri Jan 10 23:51:55 2020
Downloaded: Fri Jan 10 23:51:49 2020
Not using downloaded mysql-tools-community/repomd.xml because it is older than what we have:
Current : Sat Jan 11 02:32:38 2020
Downloaded: Sat Jan 11 02:32:21 2020
mysql-cluster-7.5-community/x86_64 MySQL Cluster 7.5 Community disabled
mysql-cluster-7.5-community-source MySQL Cluster 7.5 Community - disabled
mysql-cluster-7.6-community/x86_64 MySQL Cluster 7.6 Community disabled
mysql-cluster-7.6-community-source MySQL Cluster 7.6 Community - disabled
mysql-cluster-8.0-community/x86_64 MySQL Cluster 8.0 Community disabled
mysql-cluster-8.0-community-source MySQL Cluster 8.0 Community - disabled
mysql-connectors-community/x86_64 MySQL Connectors Community enabled: 42
mysql-connectors-community-source MySQL Connectors Community - disabled
mysql-tools-community/x86_64 MySQL Tools Community enabled: 19
mysql-tools-community-source MySQL Tools Community - Sourc disabled
mysql-tools-preview/x86_64 MySQL Tools Preview disabled
mysql-tools-preview-source MySQL Tools Preview - Source disabled
mysql55-community/x86_64 MySQL 5.5 Community Server disabled
mysql55-community-source MySQL 5.5 Community Server - disabled
mysql56-community/x86_64 MySQL 5.6 Community Server disabled
mysql56-community-source MySQL 5.6 Community Server - disabled
mysql57-community/x86_64 MySQL 5.7 Community Server enabled: 404
mysql57-community-source MySQL 5.7 Community Server - disabled
mysql80-community/x86_64 MySQL 8.0 Community Server disabled
mysql80-community-source MySQL 8.0 Community Server - disabled
9.查看支持的mysql仓库
cat /etc/yum.repos.d/mysql-community.repo
10.开始安装
yum install mysql-community-server
11.开机启动
systemctl enable mysqld
12.查看是否启动
systemctl list-unit-files |grep 'mysql*'
13.查看随机密码
more /var/log/mysqld.log
2020-01-20T09:07:17.899328Z 1 [Note] A temporary password is generated for root@localhost: 1Xl(r!s4S0jx
14.登录mysql
mysql -u root -p
输入密码
15.修改密码
在执行指令前必须修改密码 不然会报错
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
又提示密码太简单了
mysql> alter user 'root'@'localhost' identified by '123456';
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
所以先设置一个复杂密码,修改密码策略后再修改成简单密码
查看密码策略,这里要求长度为8,有大小写,特殊字符,策略中等。
mysql> show variables like '%password%';
+----------------------------------------+-----------------+
| Variable_name | Value |
+----------------------------------------+-----------------+
| default_password_lifetime | 0 |
| disconnect_on_expired_password | ON |
| log_builtin_as_identified_by_password | OFF |
| mysql_native_password_proxy_users | OFF |
| old_passwords | 0 |
| report_password | |
| sha256_password_auto_generate_rsa_keys | ON |
| sha256_password_private_key_path | private_key.pem |
| sha256_password_proxy_users | OFF |
| sha256_password_public_key_path | public_key.pem |
| validate_password_check_user_name | OFF |
| validate_password_dictionary_file | |
| validate_password_length | 8 |
| validate_password_mixed_case_count | 1 |
| validate_password_number_count | 1 |
| validate_password_policy | MEDIUM |
| validate_password_special_char_count | 1 |
+----------------------------------------+-----------------+
17 rows in set (0.13 sec)
修改策略后重新设置密码
set global validate_password_length = 6
set global validate_password_policy = LOW;
alter user 'root'@'localhost' identified by '123456';
16.退出登录试下新密码
quit
mysql -u root -p
输入密码:123456 登录成功
17.开启远程登录权限
grant all privileges on *.* to root@'%' identified by "123456";
flush privileges; 刷新
第一个* 数据库
第二个* 表
root 用户
% 所有id
18.其他指令
show databases; 查看所有数据库
use mysql; 指定操作的数据库
show tables; 查看所有表
desc table_name; 查看表结构
select host,user,authentication_string from user; 查看用户表
以上是关于centos7下mysql5.7的安装的主要内容,如果未能解决你的问题,请参考以下文章