赞
踩
随笔记录
背景介绍:重装Centos7 系统,没有安装mysql
目录
2. MySQL官网下载适用于centos7的mysql安装包
2.3.7.4 首先需要设置密码的验证强度等级,设置 validate_password_policy 的全局参数为 LOW
2.3.7.5 当前密码长度为 8 ,可以设置为4位的密码:
2.3.9.3 修改Mysql 远程连接 :修改root用户的host值,并刷新mysql数据库
2.3.9.4 Navicate 远程连接Mysql8.0 成功
1. 查看否有MariaDB
与MySQL
-
- # 查本地是否有相应的mysql(或者先检查是否有mariadb存在)
-
-
- [root@localhost Tools]# ps ajx|grep mariadb
- 210088 228505 228504 210088 pts/1 228504 S+ 0 0:00 grep --color=auto mariadb
- [root@localhost Tools]#
- [root@localhost Tools]# ps ajx|grep mysql
- 210088 228537 228536 210088 pts/1 228536 S+ 0 0:00 grep --color=auto mysql
- [root@localhost Tools]#
-
-
- 注意: MariaDB是一种开源的关系型数据库管理系统(RDBMS),它是MySQL的一个分支。
- 它提供了与MySQL高度兼容的功能和语法,同时还具有一些额外的功能和改进
- # uname -m
- or
- # arch
-
- [root@localhost Tools]# uname -m
- x86_64
- [root@localhost Tools]#
- [root@localhost Tools]# arch
- x86_64 # linux 服务器 x86_64
- [root@localhost Tools]#
- [root@localhost Tools]# cat /etc/centos-release
- CentOS Linux release 7.9.2009 (Core)
- [root@localhost Tools]#
- [root@localhost Tools]#
- [root@localhost Tools]# cat /etc/redhat-release
- CentOS Linux release 7.9.2009 (Core)
- [root@localhost Tools]#
- [root@localhost Tools]#
官方的软件仓库下载速度可能较慢,建议采用国内的镜像。如果采用清华镜像,下面链接的方法:
mysql | 镜像站使用帮助 | 清华大学开源软件镜像站 | Tsinghua Open Source Mirror
- # /etc/yum.repos.d/ 路径下新建 mysql-community.repo
- [root@localhost Tools]# cd /etc/yum.repos.d/
- [root@localhost yum.repos.d]# ls
- CentOS-Base.repo CentOS-fasttrack.repo CentOS-Vault.repo epel.repo
- CentOS-CR.repo CentOS-Media.repo CentOS-x86_64-kernel.repo epel-testing.repo
- CentOS-Debuginfo.repo CentOS-Sources.repo docker-ce.repo
- [root@localhost yum.repos.d]#
- [root@localhost yum.repos.d]# vi mysql-community.repo
- [root@localhost yum.repos.d]#
- [root@localhost yum.repos.d]#
-
-
- [root@localhost Tools]# cat /etc/yum.repos.d/mysql-community.repo
- [mysql-connectors-community]
- name=MySQL Connectors Community
- baseurl=https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql-connectors-community-el7-$basearch/
- enabled=1
- gpgcheck=1
- gpgkey=https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
-
- [mysql-tools-community]
- name=MySQL Tools Community
- baseurl=https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql-tools-community-el7-$basearch/
- enabled=1
- gpgcheck=1
- gpgkey=https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
-
- [mysql-8.0-community]
- name=MySQL 8.0 Community Server
- baseurl=https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql-8.0-community-el7-$basearch/
- enabled=1
- gpgcheck=1
- gpgkey=https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
- [root@localhost Tools]#
- # yum install mysql-community-server
- # 以上命令除了会安装 mysql-community-server (MySQL server),还会安装它依赖的其它软件包。
-
- [root@localhost Tools]# yum install mysql-community-server
- Loaded plugins: fastestmirror, langpacks
- Loading mirror speeds from cached hostfile
- * base: mirrors.bfsu.edu.cn
- * epel: mirrors.bfsu.edu.cn
- * extras: mirrors.bfsu.edu.cn
- * updates: mirrors.aliyun.com
- mysql-8.0-community | 3.0 kB 00:00:00
- mysql-connectors-community | 3.0 kB 00:00:00
- mysql-tools-community | 3.0 kB 00:00:00
- (1/3): mysql-tools-community/x86_64/primary_db | 98 kB 00:00:00
- (2/3): mysql-8.0-community/x86_64/primary_db | 279 kB 00:00:00
- (3/3): mysql-connectors-community/x86_64/primary_db | 109 kB 00:00:00
- Resolving Dependencies
- --> Running transaction check
- ---> Package mysql-community-server.x86_64 0:8.0.35-1.el7 will be installed
- --> Processing Dependency: mysql-community-common(x86-64) = 8.0.35-1.el7 for package: mysql-community-server-8.0.35-1.el7.x86_64
- --> Processing Dependency: mysql-community-icu-data-files = 8.0.35-1.el7 for package: mysql-community-server-8.0.35-1.el7.x86_64
- --> Processing Dependency: mysql-community-client(x86-64) >= 8.0.11 for package: mysql-community-server-8.0.35-1.el7.x86_64
- --> Running transaction check
- ---> Package mysql-community-client.x86_64 0:8.0.35-1.el7 will be installed
- --> Processing Dependency: mysql-community-client-plugins = 8.0.35-1.el7 for package: mysql-community-client-8.0.35-1.el7.x86_64
- --> Processing Dependency: mysql-community-libs(x86-64) >= 8.0.11 for package: mysql-community-client-8.0.35-1.el7.x86_64
- ---> Package mysql-community-common.x86_64 0:8.0.35-1.el7 will be installed
- ---> Package mysql-community-icu-data-files.x86_64 0:8.0.35-1.el7 will be installed
- --> Running transaction check
- ---> Package mariadb-libs.x86_64 1:5.5.68-1.el7 will be obsoleted
- --> Processing Dependency: libmysqlclient.so.18()(64bit) for package: 2:postfix-2.10.1-9.el7.x86_64
- --> Processing Dependency: libmysqlclient.so.18(libmysqlclient_18)(64bit) for package: 2:postfix-2.10.1-9.el7.x86_64
- ---> Package mysql-community-client-plugins.x86_64 0:8.0.35-1.el7 will be installed
- ---> Package mysql-community-libs.x86_64 0:8.0.35-1.el7 will be obsoleting
- --> Running transaction check
- ---> Package mysql-community-libs-compat.x86_64 0:8.0.35-1.el7 will be obsoleting
- --> Finished Dependency Resolution
-
- Dependencies Resolved
-
- ===========================================================================================
- Package Arch Version Repository Size
- ===========================================================================================
- Installing:
- mysql-community-libs x86_64 8.0.35-1.el7 mysql-8.0-community 1.5 M
- replacing mariadb-libs.x86_64 1:5.5.68-1.el7
- mysql-community-libs-compat x86_64 8.0.35-1.el7 mysql-8.0-community 669 k
- replacing mariadb-libs.x86_64 1:5.5.68-1.el7
- mysql-community-server x86_64 8.0.35-1.el7 mysql-8.0-community 64 M
- Installing for dependencies:
- mysql-community-client x86_64 8.0.35-1.el7 mysql-8.0-community 16 M
- mysql-community-client-plugins x86_64 8.0.35-1.el7 mysql-8.0-community 3.5 M
- mysql-community-common x86_64 8.0.35-1.el7 mysql-8.0-community 665 k
- mysql-community-icu-data-files x86_64 8.0.35-1.el7 mysql-8.0-community 2.2 M
-
- Transaction Summary
- ===========================================================================================
- Install 3 Packages (+4 Dependent packages)
-
- Total download size: 89 M
- Is this ok [y/d/N]: y # y
- Downloading packages:
- warning: /var/cache/yum/x86_64/7/mysql-8.0-community/packages/mysql-community-client-plugins-8.0.35-1.el7.x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID 3a79bd29: NOKEY
- Public key for mysql-community-client-plugins-8.0.35-1.el7.x86_64.rpm is not installed
- (1/7): mysql-community-client-plugins-8.0.35-1.el7.x86_64.rpm | 3.5 MB 00:00:09
- (2/7): mysql-community-common-8.0.35-1.el7.x86_64.rpm | 665 kB 00:00:00
- (3/7): mysql-community-icu-data-files-8.0.35-1.el7.x86_64.rpm | 2.2 MB 00:00:03
- (4/7): mysql-community-libs-8.0.35-1.el7.x86_64.rpm | 1.5 MB 00:00:02
- (5/7): mysql-community-libs-compat-8.0.35-1.el7.x86_64.rpm | 669 kB 00:00:00
- (6/7): mysql-community-client-8.0.35-1.el7.x86_64.rpm | 16 MB 00:00:40
- (7/7): mysql-community-server-8.0.35-1.el7.x86_64.rpm | 64 MB 00:01:18
- -------------------------------------------------------------------------------------------
- Total 944 kB/s | 89 MB 00:01:36
- Retrieving key from https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
- Importing GPG key 0x3A79BD29:
- Userid : "MySQL Release Engineering <mysql-build@oss.oracle.com>"
- Fingerprint: 859b e8d7 c586 f538 430b 19c2 467b 942d 3a79 bd29
- From : https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
- Is this ok [y/N]: y # y
- Running transaction check
- Running transaction test
- Transaction test succeeded
- Running transaction
- Installing : mysql-community-common-8.0.35-1.el7.x86_64 1/8
- Installing : mysql-community-client-plugins-8.0.35-1.el7.x86_64 2/8
- Installing : mysql-community-libs-8.0.35-1.el7.x86_64 3/8
- Installing : mysql-community-client-8.0.35-1.el7.x86_64 4/8
- Installing : mysql-community-icu-data-files-8.0.35-1.el7.x86_64 5/8
- Installing : mysql-community-server-8.0.35-1.el7.x86_64 6/8
- Installing : mysql-community-libs-compat-8.0.35-1.el7.x86_64 7/8
- Erasing : 1:mariadb-libs-5.5.68-1.el7.x86_64 8/8
- Verifying : mysql-community-client-plugins-8.0.35-1.el7.x86_64 1/8
- Verifying : mysql-community-common-8.0.35-1.el7.x86_64 2/8
- Verifying : mysql-community-icu-data-files-8.0.35-1.el7.x86_64 3/8
- Verifying : mysql-community-libs-8.0.35-1.el7.x86_64 4/8
- Verifying : mysql-community-client-8.0.35-1.el7.x86_64 5/8
- Verifying : mysql-community-libs-compat-8.0.35-1.el7.x86_64 6/8
- Verifying : mysql-community-server-8.0.35-1.el7.x86_64 7/8
- Verifying : 1:mariadb-libs-5.5.68-1.el7.x86_64 8/8
-
- Installed:
- mysql-community-libs.x86_64 0:8.0.35-1.el7
- mysql-community-libs-compat.x86_64 0:8.0.35-1.el7
- mysql-community-server.x86_64 0:8.0.35-1.el7
-
- Dependency Installed:
- mysql-community-client.x86_64 0:8.0.35-1.el7
- mysql-community-client-plugins.x86_64 0:8.0.35-1.el7
- mysql-community-common.x86_64 0:8.0.35-1.el7
- mysql-community-icu-data-files.x86_64 0:8.0.35-1.el7
-
- Replaced:
- mariadb-libs.x86_64 1:5.5.68-1.el7
-
- Complete!
- [root@localhost Tools]#
- [root@localhost Tools]#
- [root@localhost Tools]# systemctl start mysqld
- [root@localhost Tools]#
- # 初始化
- # mysqld --initialize
-
- [root@localhost Tools]# mysqld --initialize
- [root@localhost Tools]#
- [root@localhost Tools]# grep 'temporary password' /var/log/mysqld.log
- 2023-12-11T06:19:02.169003Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: np1bH=nX7STs
- [root@localhost Tools]#
- # 查看默认密码
- # localhost后面的最后的那一大串字符,就是密码,复制下来。
-
- [root@localhost Tools]#
- [root@localhost Tools]# grep 'temporary password' /var/log/mysqld.log
- 2023-12-11T06:19:02.169003Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: np1bH=nX7STs # 密码:np1bH=nX7STs
- [root@localhost Tools]#
-
-
-
- # 登录
- # mysql -uroot -p
-
- [root@localhost Tools]# mysql -uroot -p
- Enter password: #输入 2.3.5 查询的默认密码后回车即可登录 mysql
- Welcome to the MySQL monitor. Commands end with ; or \g.
- Your MySQL connection id is 10
- Server version: 8.0.35
-
- Copyright (c) 2000, 2023, Oracle and/or its affiliates.
-
- Oracle is a registered trademark of Oracle Corporation and/or its
- affiliates. Other names may be trademarks of their respective
- owners.
-
- Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
-
- mysql>
- #安装Mysql8.0后,第一次登录执行除修改密码的相关语句会出现如下错误(如图所示):
-
- mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'yusur666';
- ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
- mysql>
- # mysql 8.0 密码策略要求
- # 密码必须为8位,需要一个以上的小写字母和大写字母,需要一个以上的数字以及需要一个以上的特殊字符
- # 如果登录后不修改密码,基本无法做任何操作
-
- mysql> alter user 'root'@'localhost' identified by 'Yusur@666';
- Query OK, 0 rows affected (0.02 sec)
-
- mysql>
-
-
-
- mysql> show variables like 'validate%';
- +-------------------------------------------------+--------+
- | Variable_name | Value |
- +-------------------------------------------------+--------+
- | validate_password.changed_characters_percentage | 0 |
- | validate_password.check_user_name | ON |
- | 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 |
- +-------------------------------------------------+--------+
- 8 rows in set (0.00 sec)
-
- mysql>
- mysql> set global validate_password.policy=LOW;
- Query OK, 0 rows affected (0.00 sec)
-
- mysql>
- mysql> set global validate_password.length=4;
- Query OK, 0 rows affected (0.00 sec)
-
- mysql>
- mysql> show variables like 'validate%';
- +-------------------------------------------------+-------+
- | Variable_name | Value |
- +-------------------------------------------------+-------+
- | validate_password.changed_characters_percentage | 0 |
- | validate_password.check_user_name | ON |
- | validate_password.dictionary_file | |
- | validate_password.length | 4 |
- | validate_password.mixed_case_count | 1 |
- | validate_password.number_count | 1 |
- | validate_password.policy | LOW |
- | validate_password.special_char_count | 1 |
- +-------------------------------------------------+-------+
- 8 rows in set (0.01 sec)
-
- mysql>
- # alter user 'root'@'localhost' identified by '<simple new password>';
-
- mysql> alter user 'root'@'localhost' identified by 'yusur666';
- Query OK, 0 rows affected (0.02 sec)
-
- mysql>
-
-
- # 重启mysql f服务,后重新登录
- [root@localhost Tools]# systemctl restart mysqld.service
- [root@localhost Tools]#
- [root@localhost Tools]# mysql -uroot -p
- Enter password: #输入新密码
- Welcome to the MySQL monitor. Commands end with ; or \g.
- Your MySQL connection id is 8
- Server version: 8.0.35 MySQL Community Server - GPL
-
- Copyright (c) 2000, 2023, Oracle and/or its affiliates.
-
- Oracle is a registered trademark of Oracle Corporation and/or its
- affiliates. Other names may be trademarks of their respective
- owners.
-
- Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
-
- mysql>
- [root@localhost Tools]#
- [root@localhost Tools]# systemctl list-unit-files|grep mysqld
- mysqld.service enabled # 已设置为开机启动
- mysqld@.service disabled
- [root@localhost Tools]#
-
-
-
- # 如果没有设置为开机启动则执行
-
- # systemctl enable mysqld.service
Naviicate 远程连接Mysql 时出错,可能因为Mysql 没有设置远程连接,仅支持本地连接
- mysql>
- mysql> show databases;
- +--------------------+
- | Database |
- +--------------------+
- | information_schema |
- | mysql |
- | performance_schema |
- | sys |
- +--------------------+
- 4 rows in set (0.01 sec)
-
- mysql>
- mysql> use mysql;
- Reading table information for completion of table and column names
- You can turn off this feature to get a quicker startup with -A
-
- Database changed
- mysql>
-
- # select host, user from user;
-
- mysql> select host,user from user;
- +-----------+------------------+
- | host | user |
- +-----------+------------------+
- | localhost | mysql.infoschema |
- | localhost | mysql.session |
- | localhost | mysql.sys |
- | localhost | root |
- +-----------+------------------+
- 4 rows in set (0.00 sec)
-
- mysql>
-
-
- # host部分全部都是localhost,说明用户只能本地连接msyql服务
root
用户的host
值,并刷新mysql数据库- # update user set user.host=’%'where user.user=‘root’;
- # flush privileges;
-
- mysql> update user set user.host='%' where user.user='root';
- Query OK, 1 row affected (0.01 sec)
- Rows matched: 1 Changed: 1 Warnings: 0
- mysql>
- mysql> flush privileges;
- Query OK, 0 rows affected (0.00 sec)
- mysql>
- mysql> select host,user from user;
- +-----------+------------------+
- | host | user |
- +-----------+------------------+
- | % | root |
- | localhost | mysql.infoschema |
- | localhost | mysql.session |
- | localhost | mysql.sys |
- +-----------+------------------+
- 4 rows in set (0.00 sec)
- mysql>
注意:此处徐Oracel Accout,并登录
到此 Centos7 第一次安装 Mysql8.0 已完成操作
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。