当前位置:   article > 正文

Centos7 首次 安装Mysql8.0_centos 本地安装mysql

centos 本地安装mysql

随笔记录

背景介绍:重装Centos7 系统,没有安装mysql 

目录

1. 查看否有MariaDB与MySQL

2. MySQL官网下载适用于centos7的mysql安装包

2.1 查询服务器是x86_64架构还是arm架构

2.2 查系统版本

2.3 下载适用于系统版本安装包

2.3.1 国内镜像源下载安装包

2.3.2 安装 MySQL

2.3.3 运行 MySQL 

2.3.4 初始化

2.3.5 查看默认密码

2.3.6 登录

2.3.7 重置root密码

2.3.7.1 重置密码不符合mysql8.0 策略要求

2.3.7.2 重置密码符合Mysql8.0 策略要求

2.3.7.3 查看 mysql 初始的密码策略

2.3.7.4 首先需要设置密码的验证强度等级,设置 validate_password_policy 的全局参数为 LOW 

2.3.7.5 当前密码长度为 8 ,可以设置为4位的密码:

2.3.7.6 查看修改后的密码策略

2.3.7.7 修改简单密码

2.3.7.8 重启mysql 服务后,新密码登录

2.3.8  检查是否已经设置为开机启动MySQL服务

2.3.9 Mysql 设置远程

2.3.9.1  查看mysql 连接

2.3.9.2 查看可登录mysql的host

2.3.9.3  修改Mysql 远程连接 :修改root用户的host值,并刷新mysql数据库

 2.3.9.4 Navicate 远程连接Mysql8.0 成功

2.4 官网下载,太慢


1. 查看否有MariaDBMySQL

  1. # ​查本地是否有相应的mysql(或者先检查是否有mariadb存在)
  2. [root@localhost Tools]# ps ajx|grep mariadb
  3. 210088 228505 228504 210088 pts/1 228504 S+ 0 0:00 grep --color=auto mariadb
  4. [root@localhost Tools]#
  5. [root@localhost Tools]# ps ajx|grep mysql
  6. 210088 228537 228536 210088 pts/1 228536 S+ 0 0:00 grep --color=auto mysql
  7. [root@localhost Tools]#
  8. 注意: MariaDB是一种开源的关系型数据库管理系统(RDBMS),它是MySQL的一个分支。
  9. 它提供了与MySQL高度兼容的功能和语法,同时还具有一些额外的功能和改进

2. MySQL官网下载适用于centos7的mysql安装包

2.1 查询服务器是x86_64架构还是arm架构
  1. # uname -m
  2. or
  3. # arch
  4. [root@localhost Tools]# uname -m
  5. x86_64
  6. [root@localhost Tools]#
  7. [root@localhost Tools]# arch
  8. x86_64 # linux 服务器 x86_64
  9. [root@localhost Tools]#
2.2 查系统版本
  1. [root@localhost Tools]# cat /etc/centos-release
  2. CentOS Linux release 7.9.2009 (Core)
  3. [root@localhost Tools]#
  4. [root@localhost Tools]#
  5. [root@localhost Tools]# cat /etc/redhat-release
  6. CentOS Linux release 7.9.2009 (Core)
  7. [root@localhost Tools]#
  8. [root@localhost Tools]#
2.3 下载适用于系统版本安装包
2.3.1 国内镜像源下载安装包

官方的软件仓库下载速度可能较慢,建议采用国内的镜像。如果采用清华镜像,下面链接的方法:

mysql | 镜像站使用帮助 | 清华大学开源软件镜像站 | Tsinghua Open Source Mirror

  1. # /etc/yum.repos.d/ 路径下新建 mysql-community.repo
  2. [root@localhost Tools]# cd /etc/yum.repos.d/
  3. [root@localhost yum.repos.d]# ls
  4. CentOS-Base.repo CentOS-fasttrack.repo CentOS-Vault.repo epel.repo
  5. CentOS-CR.repo CentOS-Media.repo CentOS-x86_64-kernel.repo epel-testing.repo
  6. CentOS-Debuginfo.repo CentOS-Sources.repo docker-ce.repo
  7. [root@localhost yum.repos.d]#
  8. [root@localhost yum.repos.d]# vi mysql-community.repo
  9. [root@localhost yum.repos.d]#
  10. [root@localhost yum.repos.d]#
  11. [root@localhost Tools]# cat /etc/yum.repos.d/mysql-community.repo
  12. [mysql-connectors-community]
  13. name=MySQL Connectors Community
  14. baseurl=https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql-connectors-community-el7-$basearch/
  15. enabled=1
  16. gpgcheck=1
  17. gpgkey=https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
  18. [mysql-tools-community]
  19. name=MySQL Tools Community
  20. baseurl=https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql-tools-community-el7-$basearch/
  21. enabled=1
  22. gpgcheck=1
  23. gpgkey=https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
  24. [mysql-8.0-community]
  25. name=MySQL 8.0 Community Server
  26. baseurl=https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql-8.0-community-el7-$basearch/
  27. enabled=1
  28. gpgcheck=1
  29. gpgkey=https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
  30. [root@localhost Tools]#
2.3.2 安装 MySQL
  1. # yum install mysql-community-server
  2. # 以上命令除了会安装 mysql-community-server (MySQL server),还会安装它依赖的其它软件包。
  3. [root@localhost Tools]# yum install mysql-community-server
  4. Loaded plugins: fastestmirror, langpacks
  5. Loading mirror speeds from cached hostfile
  6. * base: mirrors.bfsu.edu.cn
  7. * epel: mirrors.bfsu.edu.cn
  8. * extras: mirrors.bfsu.edu.cn
  9. * updates: mirrors.aliyun.com
  10. mysql-8.0-community | 3.0 kB 00:00:00
  11. mysql-connectors-community | 3.0 kB 00:00:00
  12. mysql-tools-community | 3.0 kB 00:00:00
  13. (1/3): mysql-tools-community/x86_64/primary_db | 98 kB 00:00:00
  14. (2/3): mysql-8.0-community/x86_64/primary_db | 279 kB 00:00:00
  15. (3/3): mysql-connectors-community/x86_64/primary_db | 109 kB 00:00:00
  16. Resolving Dependencies
  17. --> Running transaction check
  18. ---> Package mysql-community-server.x86_64 0:8.0.35-1.el7 will be installed
  19. --> Processing Dependency: mysql-community-common(x86-64) = 8.0.35-1.el7 for package: mysql-community-server-8.0.35-1.el7.x86_64
  20. --> Processing Dependency: mysql-community-icu-data-files = 8.0.35-1.el7 for package: mysql-community-server-8.0.35-1.el7.x86_64
  21. --> Processing Dependency: mysql-community-client(x86-64) >= 8.0.11 for package: mysql-community-server-8.0.35-1.el7.x86_64
  22. --> Running transaction check
  23. ---> Package mysql-community-client.x86_64 0:8.0.35-1.el7 will be installed
  24. --> Processing Dependency: mysql-community-client-plugins = 8.0.35-1.el7 for package: mysql-community-client-8.0.35-1.el7.x86_64
  25. --> Processing Dependency: mysql-community-libs(x86-64) >= 8.0.11 for package: mysql-community-client-8.0.35-1.el7.x86_64
  26. ---> Package mysql-community-common.x86_64 0:8.0.35-1.el7 will be installed
  27. ---> Package mysql-community-icu-data-files.x86_64 0:8.0.35-1.el7 will be installed
  28. --> Running transaction check
  29. ---> Package mariadb-libs.x86_64 1:5.5.68-1.el7 will be obsoleted
  30. --> Processing Dependency: libmysqlclient.so.18()(64bit) for package: 2:postfix-2.10.1-9.el7.x86_64
  31. --> Processing Dependency: libmysqlclient.so.18(libmysqlclient_18)(64bit) for package: 2:postfix-2.10.1-9.el7.x86_64
  32. ---> Package mysql-community-client-plugins.x86_64 0:8.0.35-1.el7 will be installed
  33. ---> Package mysql-community-libs.x86_64 0:8.0.35-1.el7 will be obsoleting
  34. --> Running transaction check
  35. ---> Package mysql-community-libs-compat.x86_64 0:8.0.35-1.el7 will be obsoleting
  36. --> Finished Dependency Resolution
  37. Dependencies Resolved
  38. ===========================================================================================
  39. Package Arch Version Repository Size
  40. ===========================================================================================
  41. Installing:
  42. mysql-community-libs x86_64 8.0.35-1.el7 mysql-8.0-community 1.5 M
  43. replacing mariadb-libs.x86_64 1:5.5.68-1.el7
  44. mysql-community-libs-compat x86_64 8.0.35-1.el7 mysql-8.0-community 669 k
  45. replacing mariadb-libs.x86_64 1:5.5.68-1.el7
  46. mysql-community-server x86_64 8.0.35-1.el7 mysql-8.0-community 64 M
  47. Installing for dependencies:
  48. mysql-community-client x86_64 8.0.35-1.el7 mysql-8.0-community 16 M
  49. mysql-community-client-plugins x86_64 8.0.35-1.el7 mysql-8.0-community 3.5 M
  50. mysql-community-common x86_64 8.0.35-1.el7 mysql-8.0-community 665 k
  51. mysql-community-icu-data-files x86_64 8.0.35-1.el7 mysql-8.0-community 2.2 M
  52. Transaction Summary
  53. ===========================================================================================
  54. Install 3 Packages (+4 Dependent packages)
  55. Total download size: 89 M
  56. Is this ok [y/d/N]: y # y
  57. Downloading packages:
  58. 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
  59. Public key for mysql-community-client-plugins-8.0.35-1.el7.x86_64.rpm is not installed
  60. (1/7): mysql-community-client-plugins-8.0.35-1.el7.x86_64.rpm | 3.5 MB 00:00:09
  61. (2/7): mysql-community-common-8.0.35-1.el7.x86_64.rpm | 665 kB 00:00:00
  62. (3/7): mysql-community-icu-data-files-8.0.35-1.el7.x86_64.rpm | 2.2 MB 00:00:03
  63. (4/7): mysql-community-libs-8.0.35-1.el7.x86_64.rpm | 1.5 MB 00:00:02
  64. (5/7): mysql-community-libs-compat-8.0.35-1.el7.x86_64.rpm | 669 kB 00:00:00
  65. (6/7): mysql-community-client-8.0.35-1.el7.x86_64.rpm | 16 MB 00:00:40
  66. (7/7): mysql-community-server-8.0.35-1.el7.x86_64.rpm | 64 MB 00:01:18
  67. -------------------------------------------------------------------------------------------
  68. Total 944 kB/s | 89 MB 00:01:36
  69. Retrieving key from https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
  70. Importing GPG key 0x3A79BD29:
  71. Userid : "MySQL Release Engineering <mysql-build@oss.oracle.com>"
  72. Fingerprint: 859b e8d7 c586 f538 430b 19c2 467b 942d 3a79 bd29
  73. From : https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
  74. Is this ok [y/N]: y # y
  75. Running transaction check
  76. Running transaction test
  77. Transaction test succeeded
  78. Running transaction
  79. Installing : mysql-community-common-8.0.35-1.el7.x86_64 1/8
  80. Installing : mysql-community-client-plugins-8.0.35-1.el7.x86_64 2/8
  81. Installing : mysql-community-libs-8.0.35-1.el7.x86_64 3/8
  82. Installing : mysql-community-client-8.0.35-1.el7.x86_64 4/8
  83. Installing : mysql-community-icu-data-files-8.0.35-1.el7.x86_64 5/8
  84. Installing : mysql-community-server-8.0.35-1.el7.x86_64 6/8
  85. Installing : mysql-community-libs-compat-8.0.35-1.el7.x86_64 7/8
  86. Erasing : 1:mariadb-libs-5.5.68-1.el7.x86_64 8/8
  87. Verifying : mysql-community-client-plugins-8.0.35-1.el7.x86_64 1/8
  88. Verifying : mysql-community-common-8.0.35-1.el7.x86_64 2/8
  89. Verifying : mysql-community-icu-data-files-8.0.35-1.el7.x86_64 3/8
  90. Verifying : mysql-community-libs-8.0.35-1.el7.x86_64 4/8
  91. Verifying : mysql-community-client-8.0.35-1.el7.x86_64 5/8
  92. Verifying : mysql-community-libs-compat-8.0.35-1.el7.x86_64 6/8
  93. Verifying : mysql-community-server-8.0.35-1.el7.x86_64 7/8
  94. Verifying : 1:mariadb-libs-5.5.68-1.el7.x86_64 8/8
  95. Installed:
  96. mysql-community-libs.x86_64 0:8.0.35-1.el7
  97. mysql-community-libs-compat.x86_64 0:8.0.35-1.el7
  98. mysql-community-server.x86_64 0:8.0.35-1.el7
  99. Dependency Installed:
  100. mysql-community-client.x86_64 0:8.0.35-1.el7
  101. mysql-community-client-plugins.x86_64 0:8.0.35-1.el7
  102. mysql-community-common.x86_64 0:8.0.35-1.el7
  103. mysql-community-icu-data-files.x86_64 0:8.0.35-1.el7
  104. Replaced:
  105. mariadb-libs.x86_64 1:5.5.68-1.el7
  106. Complete!
  107. [root@localhost Tools]#
2.3.3 运行 MySQL 
  1. [root@localhost Tools]#
  2. [root@localhost Tools]# systemctl start mysqld
  3. [root@localhost Tools]#
2.3.4 初始化
  1. # 初始化
  2. # mysqld --initialize
  3. [root@localhost Tools]# mysqld --initialize
  4. [root@localhost Tools]#
  5. [root@localhost Tools]# grep 'temporary password' /var/log/mysqld.log
  6. 2023-12-11T06:19:02.169003Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: np1bH=nX7STs
  7. [root@localhost Tools]#
2.3.5 查看默认密码
  1. # 查看默认密码
  2. # localhost后面的最后的那一大串字符,就是密码,复制下来。
  3. [root@localhost Tools]#
  4. [root@localhost Tools]# grep 'temporary password' /var/log/mysqld.log
  5. 2023-12-11T06:19:02.169003Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: np1bH=nX7STs # 密码:np1bH=nX7STs
  6. [root@localhost Tools]#
2.3.6 登录
  1. # 登录
  2. # mysql -uroot -p
  3. [root@localhost Tools]# mysql -uroot -p
  4. Enter password: #输入 2.3.5 查询的默认密码后回车即可登录 mysql
  5. Welcome to the MySQL monitor. Commands end with ; or \g.
  6. Your MySQL connection id is 10
  7. Server version: 8.0.35
  8. Copyright (c) 2000, 2023, Oracle and/or its affiliates.
  9. Oracle is a registered trademark of Oracle Corporation and/or its
  10. affiliates. Other names may be trademarks of their respective
  11. owners.
  12. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  13. mysql>
2.3.7 重置root密码
2.3.7.1 重置密码不符合mysql8.0 策略要求
  1. #安装Mysql8.0后,第一次登录执行除修改密码的相关语句会出现如下错误(如图所示):
  2. mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'yusur666';
  3. ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
  4. mysql>
2.3.7.2 重置密码符合Mysql8.0 策略要求
  1. # mysql 8.0 密码策略要求
  2. # 密码必须为8位,需要一个以上的小写字母和大写字母,需要一个以上的数字以及需要一个以上的特殊字符
  3. # 如果登录后不修改密码,基本无法做任何操作
  4. mysql> alter user 'root'@'localhost' identified by 'Yusur@666';
  5. Query OK, 0 rows affected (0.02 sec)
  6. mysql>
2.3.7.3 查看 mysql 初始的密码策略
  1. mysql> show variables like 'validate%';
  2. +-------------------------------------------------+--------+
  3. | Variable_name | Value |
  4. +-------------------------------------------------+--------+
  5. | validate_password.changed_characters_percentage | 0 |
  6. | validate_password.check_user_name | ON |
  7. | validate_password.dictionary_file | |
  8. | validate_password.length | 8 |
  9. | validate_password.mixed_case_count | 1 |
  10. | validate_password.number_count | 1 |
  11. | validate_password.policy | MEDIUM |
  12. | validate_password.special_char_count | 1 |
  13. +-------------------------------------------------+--------+
  14. 8 rows in set (0.00 sec)
  15. mysql>
2.3.7.4 首先需要设置密码的验证强度等级,设置 validate_password_policy 的全局参数为 LOW 
  1. mysql> set global validate_password.policy=LOW;
  2. Query OK, 0 rows affected (0.00 sec)
  3. mysql>
2.3.7.5 当前密码长度为 8 ,可以设置为4位的密码:
  1. mysql> set global validate_password.length=4;
  2. Query OK, 0 rows affected (0.00 sec)
  3. mysql>
2.3.7.6 查看修改后的密码策略
  1. mysql> show variables like 'validate%';
  2. +-------------------------------------------------+-------+
  3. | Variable_name | Value |
  4. +-------------------------------------------------+-------+
  5. | validate_password.changed_characters_percentage | 0 |
  6. | validate_password.check_user_name | ON |
  7. | validate_password.dictionary_file | |
  8. | validate_password.length | 4 |
  9. | validate_password.mixed_case_count | 1 |
  10. | validate_password.number_count | 1 |
  11. | validate_password.policy | LOW |
  12. | validate_password.special_char_count | 1 |
  13. +-------------------------------------------------+-------+
  14. 8 rows in set (0.01 sec)
  15. mysql>
2.3.7.7 修改简单密码
  1. # alter user 'root'@'localhost' identified by '<simple new password>';
  2. mysql> alter user 'root'@'localhost' identified by 'yusur666';
  3. Query OK, 0 rows affected (0.02 sec)
  4. mysql>
2.3.7.8 重启mysql 服务后,新密码登录
  1. # 重启mysql f服务,后重新登录
  2. [root@localhost Tools]# systemctl restart mysqld.service
  3. [root@localhost Tools]#
  4. [root@localhost Tools]# mysql -uroot -p
  5. Enter password: #输入新密码
  6. Welcome to the MySQL monitor. Commands end with ; or \g.
  7. Your MySQL connection id is 8
  8. Server version: 8.0.35 MySQL Community Server - GPL
  9. Copyright (c) 2000, 2023, Oracle and/or its affiliates.
  10. Oracle is a registered trademark of Oracle Corporation and/or its
  11. affiliates. Other names may be trademarks of their respective
  12. owners.
  13. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  14. mysql>
2.3.8  检查是否已经设置为开机启动MySQL服务
  1. [root@localhost Tools]#
  2. [root@localhost Tools]# systemctl list-unit-files|grep mysqld
  3. mysqld.service enabled # 已设置为开机启动
  4. mysqld@.service disabled
  5. [root@localhost Tools]#
  6. # 如果没有设置为开机启动则执行
  7. # systemctl enable mysqld.service
2.3.9 Mysql 设置远程

Naviicate 远程连接Mysql 时出错,可能因为Mysql 没有设置远程连接,仅支持本地连接

2.3.9.1  查看mysql 连接
  1. mysql>
  2. mysql> show databases;
  3. +--------------------+
  4. | Database |
  5. +--------------------+
  6. | information_schema |
  7. | mysql |
  8. | performance_schema |
  9. | sys |
  10. +--------------------+
  11. 4 rows in set (0.01 sec)
  12. mysql>
  13. mysql> use mysql;
  14. Reading table information for completion of table and column names
  15. You can turn off this feature to get a quicker startup with -A
  16. Database changed
  17. mysql>
2.3.9.2 查看可登录mysql的host
  1. # select host, user from user;
  2. mysql> select host,user from user;
  3. +-----------+------------------+
  4. | host | user |
  5. +-----------+------------------+
  6. | localhost | mysql.infoschema |
  7. | localhost | mysql.session |
  8. | localhost | mysql.sys |
  9. | localhost | root |
  10. +-----------+------------------+
  11. 4 rows in set (0.00 sec)
  12. mysql>
  13. # host部分全部都是localhost,说明用户只能本地连接msyql服务
2.3.9.3  修改Mysql 远程连接 :修改root用户的host值,并刷新mysql数据库
  1. # update user set user.host=’%'where user.user=‘root’;
  2. # flush privileges;
  3. mysql> update user set user.host='%' where user.user='root';
  4. Query OK, 1 row affected (0.01 sec)
  5. Rows matched: 1 Changed: 1 Warnings: 0
  6. mysql>
  7. mysql> flush privileges;
  8. Query OK, 0 rows affected (0.00 sec)
  9. mysql>
  10. mysql> select host,user from user;
  11. +-----------+------------------+
  12. | host | user |
  13. +-----------+------------------+
  14. | % | root |
  15. | localhost | mysql.infoschema |
  16. | localhost | mysql.session |
  17. | localhost | mysql.sys |
  18. +-----------+------------------+
  19. 4 rows in set (0.00 sec)
  20. mysql>
 2.3.9.4 Navicate 远程连接Mysql8.0 成功

2.4 官网下载,太慢

 注意:此处徐Oracel Accout,并登录

 到此 Centos7 第一次安装 Mysql8.0  已完成操作

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/繁依Fanyi0/article/detail/673311
推荐阅读
相关标签
  

闽ICP备14008679号