翼度科技»论坛 编程开发 mysql 查看内容

安装MySQL8数据库

6

主题

6

帖子

18

积分

新手上路

Rank: 1

积分
18
安装MySQL8

MySQL Community Server 社区版本,开源免费,自由下载,但不提供官方技术支持,适用于大多数普通用户。
MySQL Enterprise Edition 企业版本,需付费,不能在线下载,可以试用30天。提供了更多的功能和更完备的技术支持,更适合于对数据库的功能和可靠性要求较高的企业客户。
MySQL Cluster 集群版,开源免费。用于架设集群服务器,可将几个MySQL Server封装成一个Server。需要在社区版或企业版的基础上使用。
MySQL Cluster CGE 高级集群版,需付费。
安装 mysql yum源
  1. [root@web ~]# wget https://repo.mysql.com//mysql84-community-release-el9-1.noarch.rpm
  2. [root@web ~]# yum install ./mysql84-community-release-el9-1.noarch.rpm
  3. [root@web ~]#
复制代码
安装成功后,查看MySQL版本:
  1. [root@web ~]# yum repolist all | grep mysql
  2. mysql-8.4-lts-community                      MySQL 8.4 LTS Community Server 启用
  3. mysql-8.4-lts-community-debuginfo            MySQL 8.4 LTS Community Server 禁用
  4. mysql-8.4-lts-community-source               MySQL 8.4 LTS Community Server 禁用
  5. mysql-cluster-8.0-community                  MySQL Cluster 8.0 Community    禁用
  6. mysql-cluster-8.0-community-debuginfo        MySQL Cluster 8.0 Community -  禁用
  7. mysql-cluster-8.0-community-source           MySQL Cluster 8.0 Community -  禁用
  8. mysql-cluster-8.4-lts-community              MySQL Cluster 8.4 LTS Communit 禁用
  9. mysql-cluster-8.4-lts-community-debuginfo    MySQL Cluster 8.4 LTS Communit 禁用
  10. mysql-cluster-8.4-lts-community-source       MySQL Cluster 8.4 LTS Communit 禁用
  11. mysql-cluster-innovation-community           MySQL Cluster Innovation Relea 禁用
  12. mysql-cluster-innovation-community-debuginfo MySQL Cluster Innovation Relea 禁用
  13. mysql-cluster-innovation-community-source    MySQL Cluster Innovation Relea 禁用
  14. mysql-connectors-community                   MySQL Connectors Community     启用
  15. mysql-connectors-community-debuginfo         MySQL Connectors Community - D 禁用
  16. mysql-connectors-community-source            MySQL Connectors Community - S 禁用
  17. mysql-innovation-community                   MySQL Innovation Release Commu 禁用
  18. mysql-innovation-community-debuginfo         MySQL Innovation Release Commu 禁用
  19. mysql-innovation-community-source            MySQL Innovation Release Commu 禁用
  20. mysql-tools-8.4-lts-community                MySQL Tools 8.4 LTS Community  启用
  21. mysql-tools-8.4-lts-community-debuginfo      MySQL Tools 8.4 LTS Community  禁用
  22. mysql-tools-8.4-lts-community-source         MySQL Tools 8.4 LTS Community  禁用
  23. mysql-tools-community                        MySQL Tools Community          禁用
  24. mysql-tools-community-debuginfo              MySQL Tools Community - Debugi 禁用
  25. mysql-tools-community-source                 MySQL Tools Community - Source 禁用
  26. mysql-tools-innovation-community             MySQL Tools Innovation Communi 禁用
  27. mysql-tools-innovation-community-debuginfo   MySQL Tools Innovation Communi 禁用
  28. mysql-tools-innovation-community-source      MySQL Tools Innovation Communi 禁用
  29. mysql80-community                            MySQL 8.0 Community Server     禁用
  30. mysql80-community-debuginfo                  MySQL 8.0 Community Server - D 禁用
  31. mysql80-community-source                     MySQL 8.0 Community Server - S 禁用
  32. [root@web ~]#
复制代码
安装MySQL
  1. [root@web ~]# yum install mysql-community-server
  2. 启动MySQL服务
  3. [root@web ~]# systemctl start mysqld
  4. 确认MySQL正常启动
  5. [root@web ~]# systemctl status mysqld
  6. 设置MySQL开机自启动
  7. [root@web ~]# systemctl enable mysqld
  8. 查看生成 MySQL root用户临时密码:
  9. [root@web ~]# grep 'temporary password' /var/log/mysqld.log
复制代码
修改root用户密码
  1. # 登录数据库
  2. [root@web ~]# mysql -uroot -p
  3. Enter password:
  4. Welcome to the MySQL monitor.  Commands end with ; or \g.
  5. Your MySQL connection id is 8
  6. Server version: 8.4.3
  7. Copyright (c) 2000, 2024, Oracle and/or its affiliates.
  8. Oracle is a registered trademark of Oracle Corporation and/or its
  9. affiliates. Other names may be trademarks of their respective
  10. owners.
  11. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  12. mysql>
  13. mysql>
  14. mysql>
  15. # 修改root密码
  16. mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'Password@2024';
  17. Query OK, 0 rows affected (0.01 sec)
  18. mysql>
复制代码
设置远程登录
  1. # 查看默认库
  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.00 sec)
  12. mysql>
  13. # 选择使用mysql库
  14. mysql> use mysql;
  15. Reading table information for completion of table and column names
  16. You can turn off this feature to get a quicker startup with -A
  17. Database changed
  18. mysql>
  19. # 查询用户表
  20. mysql> select host, user, authentication_string, plugin from user;
  21. +-----------+------------------+------------------------------------------------------------------------+-----------------------+
  22. | host      | user             | authentication_string                                                  | plugin                |
  23. +-----------+------------------+------------------------------------------------------------------------+-----------------------+
  24. | localhost | mysql.infoschema | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | caching_sha2_password |
  25. | localhost | mysql.session    | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | caching_sha2_password |
  26. | localhost | mysql.sys        | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | caching_sha2_password |
  27. | localhost | root             | $A$005$@c%qYYPJ~F-qAGZDHB6e7/1eEIz5VmK2O87RS12HBQpiPrZ7nVNqHX/D3 | caching_sha2_password |
  28. +-----------+------------------+------------------------------------------------------------------------+-----------------------+
  29. 4 rows in set (0.00 sec)
  30. mysql>
  31. # 修改root的授权
  32. mysql> update user set host='%' where user='root';
  33. Query OK, 1 row affected (0.00 sec)
  34. Rows matched: 1  Changed: 1  Warnings: 0
  35. mysql>
  36. # 需要执行俩次
  37. mysql> Grant all privileges on *.* to 'root'@'%';
  38. ERROR 1410 (42000): You are not allowed to create a user with GRANT
  39. mysql>
  40. mysql> Grant all privileges on *.* to 'root'@'%';
  41. Query OK, 0 rows affected (0.01 sec)
  42. mysql>
  43. # 刷新权限
  44. mysql> flush privileges;
  45. Query OK, 0 rows affected (0.01 sec)
  46. mysql>
  47. mysql>
  48. # 再次查看用户表
  49. mysql> select host, user, authentication_string, plugin from user;
  50. +-----------+------------------+------------------------------------------------------------------------+-----------------------+
  51. | host      | user             | authentication_string                                                  | plugin                |
  52. +-----------+------------------+------------------------------------------------------------------------+-----------------------+
  53. | %         | root             | $A$005$@c%qYYPJ~F-qAGZDHB6e7/1eEIz5VmK2O87RS12HBQpiPrZ7nVNqHX/D3 | caching_sha2_password |
  54. | localhost | mysql.infoschema | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | caching_sha2_password |
  55. | localhost | mysql.session    | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | caching_sha2_password |
  56. | localhost | mysql.sys        | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | caching_sha2_password |
  57. +-----------+------------------+------------------------------------------------------------------------+-----------------------+
  58. 4 rows in set (0.00 sec)
  59. mysql>
复制代码
测试连接
  1. # 使用其他主机进行登录数据库
  2. [root@k8s-master01 ~]# mysql -u root -p -h 192.168.1.130
  3. Enter password:
  4. Welcome to the MySQL monitor.  Commands end with ; or \g.
  5. Your MySQL connection id is 8
  6. Server version: 8.4.3 MySQL Community Server - GPL
  7. Copyright (c) 2000, 2024, Oracle and/or its affiliates.
  8. Oracle is a registered trademark of Oracle Corporation and/or its
  9. affiliates. Other names may be trademarks of their respective
  10. owners.
  11. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  12. mysql>
  13. mysql>
  14. mysql>
复制代码
关于
https://www.oiox.cn/
https://www.oiox.cn/index.php/start-page.html
CSDN、GitHub、51CTO、知乎、开源中国、思否、掘金、简书、华为云、阿里云、腾讯云、哔哩哔哩、今日头条、新浪微博、个人博客
全网可搜《小陈运维》
文章主要发布于微信公众号

来源:https://www.cnblogs.com/chenby/p/18553385
免责声明:由于采集信息均来自互联网,如果侵犯了您的权益,请联系我们【E-Mail:cb@itdo.tech】 我们会及时删除侵权内容,谢谢合作!

举报 回复 使用道具