赞
踩
1、操作系统:CentOS 7.6
2、安装源的软件包: mysql80-community-release-el7-3.noarch.rpm
也可以到mysql官网下载:
1、把mysql80-community-release-el7-3.noarch.rpm下载到待安装系统上:
- [root@bjAli ~]# ls
- bash mysql80-community-release-el7-3.noarch.rpm playbooks
- [root@bjAli ~]#
2、安装mysql源的软件包:
- [root@bjAli ~]# rpm -ivh mysql80-community-release-el7-3.noarch.rpm
- Preparing... ################################# [100%]
- Updating / installing...
- 1:mysql80-community-release-el7-3 ################################# [100%]
- [root@bjAli ~]#
3、修改配置文件mysql-community.repo文件
- [mysql80-community]
- name=MySQL 8.0 Community Server
- baseurl=http://repo.mysql.com/yum/mysql-8.0-community/el/7/$basearch/
- enabled=1 ==> 设置为1
- gpgcheck=0 ==> 设置为0
- gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
-
- [mysql-connectors-community]
- name=MySQL Connectors Community
- baseurl=http://repo.mysql.com/yum/mysql-connectors-community/el/7/$basearch/
- enabled=1 ==> 设置为1
- gpgcheck=0 ==> 设置为0
- gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
-
- [mysql-tools-community]
- name=MySQL Tools Community
- baseurl=http://repo.mysql.com/yum/mysql-tools-community/el/7/$basearch/
- enabled=1 ==> 设置为1
- gpgcheck=0 ==> 设置为0
- gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

4、用yum安装mysql-community-serve和mysql-community-client软件:
- [root@bjAli yum.repos.d]# yum install mysql-community-server mysql-community-client
- Loaded plugins: fastestmirror
- ...
- Resolving Dependencies
- --> Running transaction check
- ...
- --> Finished Dependency Resolution
-
- Dependencies Resolved
-
- =========================================================================================================================================
- Package Arch Version Repository Size
- =========================================================================================================================================
- Installing:
- mysql-community-client x86_64 8.0.28-1.el7 mysql80-community 53 M
- mysql-community-server x86_64 8.0.28-1.el7 mysql80-community 451 M
- Installing for dependencies:
- mysql-community-client-plugins x86_64 8.0.28-1.el7 mysql80-community 5.7 M
- mysql-community-common x86_64 8.0.28-1.el7 mysql80-community 630 k
- mysql-community-icu-data-files x86_64 8.0.28-1.el7 mysql80-community 2.1 M
- mysql-community-libs x86_64 8.0.28-1.el7 mysql80-community 4.7 M
-
- Transaction Summary
- =========================================================================================================================================
- Install 2 Packages (+4 Dependent packages)
-
- Total download size: 517 M
- Installed size: 2.4 G
- Is this ok [y/d/N]: y
- Downloading packages:
- Running transaction check
- Running transaction test
- Transaction test succeeded
- Running transaction
- ...... 5/6
- Installing : mysql-community-server-8.0.28-1.el7.x86_64 6/6
- Verifying : mysql-community-client-8.0.28-1.el7.x86_64 1/6
- Verifying : mysql-community-server-8.0.28-1.el7.x86_64 2/6
- Verifying : mysql-community-client-plugins-8.0.28-1.el7.x86_64 3/6
- Verifying : mysql-community-common-8.0.28-1.el7.x86_64 4/6
- Verifying : mysql-community-libs-8.0.28-1.el7.x86_64 5/6
- Verifying : mysql-community-icu-data-files-8.0.28-1.el7.x86_64 6/6
-
- Installed:
- mysql-community-client.x86_64 0:8.0.28-1.el7 mysql-community-server.x86_64 0:8.0.28-1.el7
-
- Dependency Installed:
- mysql-community-client-plugins.x86_64 0:8.0.28-1.el7 mysql-community-common.x86_64 0:8.0.28-1.el7
- mysql-community-icu-data-files.x86_64 0:8.0.28-1.el7 mysql-community-libs.x86_64 0:8.0.28-1.el7
-
- Complete!
-

5、启动mysql-community-server并查看运行状态:
- [root@bjAli yum.repos.d]# systemctl start mysqld
- [root@bjAli yum.repos.d]# systemctl status mysqld
- ● mysqld.service - MySQL Server
- Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
- Active: active (running) since Mon 2022-03-21 20:58:48 CST; 46s ago
- Docs: man:mysqld(8)
- http://dev.mysql.com/doc/refman/en/using-systemd.html
- Process: 27026 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
- Main PID: 27049 (mysqld)
- Status: "Server is operational"
- CGroup: /system.slice/mysqld.service
- └─27049 /usr/sbin/mysqld
-
- Mar 21 20:58:46 bjAli systemd[1]: Starting MySQL Server...
- Mar 21 20:58:48 bjAli systemd[1]: Started MySQL Server.
- [root@bjAli yum.repos.d]#

6、查看初始密码并用本地客户端进行连接:
- [root@bjAli yum.repos.d]# cat /var/log/mysqld.log | grep password
- 2022-03-20T13:32:46.555732Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: E)j2Q(B8%gbp <== 初始密码
- [root@bjAli yum.repos.d]# 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.28
-
- Copyright (c) 2000, 2022, 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>

7、在使用数据库前,需要更改用户'root'@'localhost'初始密码,然后查看数据库的现有有效用户:
- mysql> alter user 'root'@'localhost' identified by '@MYsql12345';
- Query OK, 0 rows affected (0.01 sec)
-
- 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 user,host from user;
- +------------------+-----------+
- | user | host |
- +------------------+-----------+
- | mysql.infoschema | localhost |
- | mysql.session | localhost |
- | mysql.sys | localhost |
- | root | localhost |
- +------------------+-----------+
- 4 rows in set (0.00 sec)
-
- mysql>

8、退出本地数据库连接,然后用新设置的密码进程本地登录测试:
- mysql> quit
- Bye
- [root@bjAli yum.repos.d]# mysql -uroot -p
- Enter password:
- Welcome to the MySQL monitor. Commands end with ; or \g.
- Your MySQL connection id is 11
- Server version: 8.0.28 MySQL Community Server - GPL
-
- Copyright (c) 2000, 2022, 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>

9、创建一个可以远程登录的用户:
- mysql>
- mysql> create user 'dbuser'@'%' identified by '@MYsql12345'; % 创建一个可以远程登录的用户
- Query OK, 0 rows affected (0.01 sec)
-
- mysql> show grants for 'dbuser'@'%'; # 显示新创建用户的权限
- +------------------------------------+
- | Grants for dbuser@% |
- +------------------------------------+
- | GRANT USAGE ON *.* TO `dbuser`@`%` |
- +------------------------------------+
- 1 row in set (0.00 sec)
-
- mysql> grant all privileges on *.* to 'dbuser'@'%'; # 对新创建用户进行授权
- Query OK, 0 rows affected (0.01 sec)
-
- mysql> flush privileges;
- Query OK, 0 rows affected (0.01 sec)
-
- 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 user,host from user; # 查看新建用户是否存在
- +------------------+-----------+
- | user | host |
- +------------------+-----------+
- | dbuser | % |
- | mysql.infoschema | localhost |
- | mysql.session | localhost |
- | mysql.sys | localhost |
- | root | localhost |
- +------------------+-----------+
- 5 rows in set (0.00 sec)
-
- mysql>

10、测试远程连接:
1) 安装mysql官方软件:MySQL Workbench 8.0 CE
2) 启动软件:选择软件菜单栏Database->Connect to Database ...选项
3) 在弹出的窗口中填入数据库服务器的IP地址以及连接数据库所用的用户名:
4)在密码栏输入,为对应用户设置的密码:
5) 如果没有错误,则回显示以下一个sql语句编辑窗口:
6)按下图所示的1,2,3步骤进行操作,测试数据库查询,可以显示出查询结果为5个数据用户:
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。