当前位置:   article > 正文

mysql8.0安装详解

mysql8.0安装详解

一、安装前准备

1、操作系统:CentOS 7.6

2、安装源的软件包: mysql80-community-release-el7-3.noarch.rpm

下载路径:mysql8在线安装源-Linux文档类资源-CSDN下载mysql8的CentOS7安装源更多下载资源、学习资料请访问CSDN下载频道.https://download.csdn.net/download/yuyuyuliang00/85014075

也可以到mysql官网下载:

二、安装步骤:

1、把mysql80-community-release-el7-3.noarch.rpm下载到待安装系统上:

  1. [root@bjAli ~]# ls
  2. bash mysql80-community-release-el7-3.noarch.rpm playbooks
  3. [root@bjAli ~]#

2、安装mysql源的软件包:

  1. [root@bjAli ~]# rpm -ivh mysql80-community-release-el7-3.noarch.rpm
  2. Preparing... ################################# [100%]
  3. Updating / installing...
  4. 1:mysql80-community-release-el7-3 ################################# [100%]
  5. [root@bjAli ~]#

3、修改配置文件mysql-community.repo文件

  1. [mysql80-community]
  2. name=MySQL 8.0 Community Server
  3. baseurl=http://repo.mysql.com/yum/mysql-8.0-community/el/7/$basearch/
  4. enabled=1 ==> 设置为1
  5. gpgcheck=0 ==> 设置为0
  6. gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
  7. [mysql-connectors-community]
  8. name=MySQL Connectors Community
  9. baseurl=http://repo.mysql.com/yum/mysql-connectors-community/el/7/$basearch/
  10. enabled=1 ==> 设置为1
  11. gpgcheck=0 ==> 设置为0
  12. gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
  13. [mysql-tools-community]
  14. name=MySQL Tools Community
  15. baseurl=http://repo.mysql.com/yum/mysql-tools-community/el/7/$basearch/
  16. enabled=1 ==> 设置为1
  17. gpgcheck=0 ==> 设置为0
  18. gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

4、用yum安装mysql-community-serve和mysql-community-client软件:

  1. [root@bjAli yum.repos.d]# yum install mysql-community-server mysql-community-client
  2. Loaded plugins: fastestmirror
  3. ...
  4. Resolving Dependencies
  5. --> Running transaction check
  6. ...
  7. --> Finished Dependency Resolution
  8. Dependencies Resolved
  9. =========================================================================================================================================
  10. Package Arch Version Repository Size
  11. =========================================================================================================================================
  12. Installing:
  13. mysql-community-client x86_64 8.0.28-1.el7 mysql80-community 53 M
  14. mysql-community-server x86_64 8.0.28-1.el7 mysql80-community 451 M
  15. Installing for dependencies:
  16. mysql-community-client-plugins x86_64 8.0.28-1.el7 mysql80-community 5.7 M
  17. mysql-community-common x86_64 8.0.28-1.el7 mysql80-community 630 k
  18. mysql-community-icu-data-files x86_64 8.0.28-1.el7 mysql80-community 2.1 M
  19. mysql-community-libs x86_64 8.0.28-1.el7 mysql80-community 4.7 M
  20. Transaction Summary
  21. =========================================================================================================================================
  22. Install 2 Packages (+4 Dependent packages)
  23. Total download size: 517 M
  24. Installed size: 2.4 G
  25. Is this ok [y/d/N]: y
  26. Downloading packages:
  27. Running transaction check
  28. Running transaction test
  29. Transaction test succeeded
  30. Running transaction
  31. ...... 5/6
  32. Installing : mysql-community-server-8.0.28-1.el7.x86_64 6/6
  33. Verifying : mysql-community-client-8.0.28-1.el7.x86_64 1/6
  34. Verifying : mysql-community-server-8.0.28-1.el7.x86_64 2/6
  35. Verifying : mysql-community-client-plugins-8.0.28-1.el7.x86_64 3/6
  36. Verifying : mysql-community-common-8.0.28-1.el7.x86_64 4/6
  37. Verifying : mysql-community-libs-8.0.28-1.el7.x86_64 5/6
  38. Verifying : mysql-community-icu-data-files-8.0.28-1.el7.x86_64 6/6
  39. Installed:
  40. mysql-community-client.x86_64 0:8.0.28-1.el7 mysql-community-server.x86_64 0:8.0.28-1.el7
  41. Dependency Installed:
  42. mysql-community-client-plugins.x86_64 0:8.0.28-1.el7 mysql-community-common.x86_64 0:8.0.28-1.el7
  43. mysql-community-icu-data-files.x86_64 0:8.0.28-1.el7 mysql-community-libs.x86_64 0:8.0.28-1.el7
  44. Complete!

5、启动mysql-community-server并查看运行状态:

  1. [root@bjAli yum.repos.d]# systemctl start mysqld
  2. [root@bjAli yum.repos.d]# systemctl status mysqld
  3. ● mysqld.service - MySQL Server
  4. Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
  5. Active: active (running) since Mon 2022-03-21 20:58:48 CST; 46s ago
  6. Docs: man:mysqld(8)
  7. http://dev.mysql.com/doc/refman/en/using-systemd.html
  8. Process: 27026 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
  9. Main PID: 27049 (mysqld)
  10. Status: "Server is operational"
  11. CGroup: /system.slice/mysqld.service
  12. └─27049 /usr/sbin/mysqld
  13. Mar 21 20:58:46 bjAli systemd[1]: Starting MySQL Server...
  14. Mar 21 20:58:48 bjAli systemd[1]: Started MySQL Server.
  15. [root@bjAli yum.repos.d]#

6、查看初始密码并用本地客户端进行连接:

  1. [root@bjAli yum.repos.d]# cat /var/log/mysqld.log | grep password
  2. 2022-03-20T13:32:46.555732Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: E)j2Q(B8%gbp <== 初始密码
  3. [root@bjAli yum.repos.d]# mysql -uroot -p
  4. Enter password: <==输入查询到的初始密码后回车,连接成功
  5. Welcome to the MySQL monitor. Commands end with ; or \g.
  6. Your MySQL connection id is 8
  7. Server version: 8.0.28
  8. Copyright (c) 2000, 2022, 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>

7、在使用数据库前,需要更改用户'root'@'localhost'初始密码,然后查看数据库的现有有效用户:

  1. mysql> alter user 'root'@'localhost' identified by '@MYsql12345';
  2. Query OK, 0 rows affected (0.01 sec)
  3. mysql> use mysql;
  4. Reading table information for completion of table and column names
  5. You can turn off this feature to get a quicker startup with -A
  6. Database changed
  7. mysql> select user,host from user;
  8. +------------------+-----------+
  9. | user | host |
  10. +------------------+-----------+
  11. | mysql.infoschema | localhost |
  12. | mysql.session | localhost |
  13. | mysql.sys | localhost |
  14. | root | localhost |
  15. +------------------+-----------+
  16. 4 rows in set (0.00 sec)
  17. mysql>

8、退出本地数据库连接,然后用新设置的密码进程本地登录测试:

  1. mysql> quit
  2. Bye
  3. [root@bjAli yum.repos.d]# mysql -uroot -p
  4. Enter password:
  5. Welcome to the MySQL monitor. Commands end with ; or \g.
  6. Your MySQL connection id is 11
  7. Server version: 8.0.28 MySQL Community Server - GPL
  8. Copyright (c) 2000, 2022, 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>

9、创建一个可以远程登录的用户:

  1. mysql>
  2. mysql> create user 'dbuser'@'%' identified by '@MYsql12345'; % 创建一个可以远程登录的用户
  3. Query OK, 0 rows affected (0.01 sec)
  4. mysql> show grants for 'dbuser'@'%'; # 显示新创建用户的权限
  5. +------------------------------------+
  6. | Grants for dbuser@% |
  7. +------------------------------------+
  8. | GRANT USAGE ON *.* TO `dbuser`@`%` |
  9. +------------------------------------+
  10. 1 row in set (0.00 sec)
  11. mysql> grant all privileges on *.* to 'dbuser'@'%'; # 对新创建用户进行授权
  12. Query OK, 0 rows affected (0.01 sec)
  13. mysql> flush privileges;
  14. Query OK, 0 rows affected (0.01 sec)
  15. mysql> use mysql;
  16. Reading table information for completion of table and column names
  17. You can turn off this feature to get a quicker startup with -A
  18. Database changed
  19. mysql> select user,host from user; # 查看新建用户是否存在
  20. +------------------+-----------+
  21. | user | host |
  22. +------------------+-----------+
  23. | dbuser | % |
  24. | mysql.infoschema | localhost |
  25. | mysql.session | localhost |
  26. | mysql.sys | localhost |
  27. | root | localhost |
  28. +------------------+-----------+
  29. 5 rows in set (0.00 sec)
  30. mysql>

10、测试远程连接:

1) 安装mysql官方软件:MySQL Workbench 8.0 CE

2) 启动软件:选择软件菜单栏Database->Connect to Database ...选项

3) 在弹出的窗口中填入数据库服务器的IP地址以及连接数据库所用的用户名:

4)在密码栏输入,为对应用户设置的密码:

 

5) 如果没有错误,则回显示以下一个sql语句编辑窗口:

6)按下图所示的1,2,3步骤进行操作,测试数据库查询,可以显示出查询结果为5个数据用户:

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

闽ICP备14008679号