首页 > 数据库 >Linux下rpm安装MySQL及配置

Linux下rpm安装MySQL及配置

时间:2023-01-04 15:12:40浏览次数:44  
标签:8.0 root Linux 28 community mysqld mysql MySQL rpm

Linux下rpm安装MySQL及配置

xupeng1644

已于 2022-03-22 11:38:47 修改

2747
收藏 15
分类专栏: Linux 文章标签: rpm MySQL Linux
版权

Linux
专栏收录该内容
55 篇文章1 订阅
订阅专栏
下载
下载地址为:https://downloads.mysql.com/archives/community/,选择版本8.0.16,操作系统为CentOS 8,所以选择Red Hat Enterprise Linux/Oracle Linux, 下面的具体版本选择Red Hat Enterprise 8/ Oracle Linux 8 (x86, 64-bit), PRM Bundle,它包含了安装MySQL8.0.27的所有依赖。

 

文件上传到CentOS步骤略过。(当然也可以直接使用wget下载,就不需要再就行上传)
下载完成后,使用命令tar -xvf mysql-8.0.16-2.el7.x86_64.rpm-bundle.tar解压缩文件。

[root@instance-1apocjsh ~]# tar -xvf mysql-8.0.28-1.el8.x86_64.rpm-bundle.tar
mysql-community-client-8.0.28-1.el8.x86_64.rpm
mysql-community-client-debuginfo-8.0.28-1.el8.x86_64.rpm
mysql-community-client-plugins-8.0.28-1.el8.x86_64.rpm
mysql-community-client-plugins-debuginfo-8.0.28-1.el8.x86_64.rpm
mysql-community-common-8.0.28-1.el8.x86_64.rpm
mysql-community-debuginfo-8.0.28-1.el8.x86_64.rpm
mysql-community-debugsource-8.0.28-1.el8.x86_64.rpm
mysql-community-devel-8.0.28-1.el8.x86_64.rpm
mysql-community-icu-data-files-8.0.28-1.el8.x86_64.rpm
mysql-community-libs-8.0.28-1.el8.x86_64.rpm
mysql-community-libs-debuginfo-8.0.28-1.el8.x86_64.rpm
mysql-community-server-8.0.28-1.el8.x86_64.rpm
mysql-community-server-debug-8.0.28-1.el8.x86_64.rpm
mysql-community-server-debug-debuginfo-8.0.28-1.el8.x86_64.rpm
mysql-community-server-debuginfo-8.0.28-1.el8.x86_64.rpm
mysql-community-test-8.0.28-1.el8.x86_64.rpm
mysql-community-test-debuginfo-8.0.28-1.el8.x86_64.rpm


安装
直接进行强制安装。因为逐个安装,很容易因为递进依赖,而报一堆错,需要下载一堆特别多的包。

[root@instance-1apocjsh ~]# rpm -ivh *.rpm --nodeps --force
warning: mysql-community-client-8.0.28-1.el8.x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID 3a79bd29: NOKEY
Verifying... ################################# [100%]
Preparing... ################################# [100%]
Updating / installing...
1:mysql-community-debugsource-8.0.2################################# [ 6%]
2:mysql-community-debuginfo-8.0.28-################################# [ 12%]
3:mysql-community-common-8.0.28-1.e################################# [ 18%]
4:mysql-community-client-plugins-8.################################# [ 24%]
5:mysql-community-libs-8.0.28-1.el8################################# [ 29%]
6:mysql-community-client-8.0.28-1.e################################# [ 35%]
7:mysql-community-icu-data-files-8.################################# [ 41%]
8:mysql-community-server-8.0.28-1.e################################# [ 47%]
9:mysql-community-server-debug-8.0.################################# [ 53%]
10:mysql-community-test-8.0.28-1.el8################################# [ 59%]
11:mysql-community-devel-8.0.28-1.el################################# [ 65%]
12:mysql-community-client-debuginfo-################################# [ 71%]
13:mysql-community-client-plugins-de################################# [ 76%]
14:mysql-community-libs-debuginfo-8.################################# [ 82%]
15:mysql-community-server-debug-debu################################# [ 88%]
16:mysql-community-server-debuginfo-################################# [ 94%]
17:mysql-community-test-debuginfo-8.################################# [100%]


验证
[root@instance-1apocjsh ~]# whereis mysql
mysql: /usr/bin/mysql /usr/lib64/mysql /usr/include/mysql /usr/share/man/man1/mysql.1.gz
1
2
可以看到,MySQL的安装路径为/usr/bin/mysql,其配套的mysqlclient库头文件位于/usr/include/mysql,库文件位于/user/lib64/mysql。

启动
查看服务状态
[root@instance-1apocjsh ~]# systemctl status mysqld
[root@instance-1apocjsh ~]# systemctl status mysqld
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: inactive (dead)
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html

初始化数据库
[root@instance-1apocjsh ~]# mysqld --initialize --console
1
目录授权
[root@instance-1apocjsh ~]# chown -R mysql:mysql /var/lib/mysql/
1
启动服务
[root@instance-1apocjsh ~]# systemctl start mysqld
[root@instance-1apocjsh ~]# systemctl status mysqld
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: active (running) since Sun 2022-03-20 14:50:25 CST; 32s ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Process: 26309 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
Main PID: 26341 (mysqld)
Status: "Server is operational"
Tasks: 38 (limit: 12437)
Memory: 418.6M
CGroup: /system.slice/mysqld.service
└─26341 /usr/sbin/mysqld

Mar 20 14:50:01 instance-1apocjsh systemd[1]: Starting MySQL Server...
Mar 20 14:50:25 instance-1apocjsh systemd[1]: Started MySQL Server.

配置
获取随机的root密码
MySQL安装后,会给root一个随机密码,可以通过命令cat /var/log/mysqld.log获取。

[root@instance-1apocjsh ~]# cat /var/log/mysqld.log
2022-03-20T06:48:24.116051Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.28) initializing of server in progress as process 26232
2022-03-20T06:48:24.149740Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2022-03-20T06:48:25.455375Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2022-03-20T06:48:26.791344Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: ;#VyPqLEl4lp
2022-03-20T06:50:24.062843Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.28) starting as process 26341
2022-03-20T06:50:24.085146Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2022-03-20T06:50:24.628213Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2022-03-20T06:50:25.003093Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2022-03-20T06:50:25.003134Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
2022-03-20T06:50:25.021975Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.28' socket: '/var/lib/mysql/mysql.sock' port: 3306 MySQL Community Server - GPL.
2022-03-20T06:50:25.022045Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '::' port: 33060, socket: /var/run/mysqld/mysqlx.sock

可以得到这次给出的root密码为;#VyPqLEl4lp。

修改root密码为123456
使用mysql -u root -p命令输入给出的随机root密码进行登录,然后使用ALTER USER 'root'@'localhost' IDENTIFIED BY '123456'将root密码修改为123456。

[root@instance-1apocjsh ~]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 11
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> ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';

root密码就修改成为了123456。

授权远程连接
依次使用命令

SHOW databases;
USE mysql;
UPDATE user SET host = "%" WHERE user='root';
SELECT host, user, authentication_string, plugin FROM user;
FLUSH privileges;

mysql> SHOW databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 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 host, user, authentication_string, plugin FROM user;
+-----------+------------------+------------------------------------------------------------------------+-----------------------+
| host | user | authentication_string | plugin |
+-----------+------------------+------------------------------------------------------------------------+-----------------------+
| localhost | mysql.infoschema | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | caching_sha2_password |
| localhost | mysql.session | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | caching_sha2_password |
| localhost | mysql.sys | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | caching_sha2_password |
| localhost | root | $A$005$mB'pF!O*'MfcWDOGjH.Pvt4PmAkNGovLizrlKcxOTs8BMDkm9Ybu/XiV9 | caching_sha2_password |
+-----------+------------------+------------------------------------------------------------------------+-----------------------+
4 rows in set (0.00 sec)

mysql> UPDATE user SET host = "%" WHERE user='root';
Query OK, 1 row affected (0.01 sec)
Rows matched: 1 Changed: 1 Warnings: 0

mysql> SELECT host, user, authentication_string, plugin FROM user
-> ;
+-----------+------------------+------------------------------------------------------------------------+-----------------------+
| host | user | authentication_string | plugin |
+-----------+------------------+------------------------------------------------------------------------+-----------------------+
| % | root | $A$005$mB'pF!O*'MfcWDOGjH.Pvt4PmAkNGovLizrlKcxOTs8BMDkm9Ybu/XiV9 | caching_sha2_password |
| localhost | mysql.infoschema | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | caching_sha2_password |
| localhost | mysql.session | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | caching_sha2_password |
| localhost | mysql.sys | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | caching_sha2_password |
+-----------+------------------+------------------------------------------------------------------------+-----------------------+
4 rows in set (0.00 sec)

mysql> FLUSH privileges;
Query OK, 0 rows affected (0.00 sec)



远程登录验证
使用Navicat远程连接MySQL, 测试连接,连接成功提示如下:

 

参考
Centos7离线安装mysql8
————————————————
版权声明:本文为CSDN博主「xupeng1644」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/xp178171640/article/details/123611639

标签:8.0,root,Linux,28,community,mysqld,mysql,MySQL,rpm
From: https://www.cnblogs.com/yaoyangding/p/17024864.html

相关文章

  • linux动态库加载相关
    查看编译时会链接的动态库ldconfig-v|greplibCmp添加编译时的动态链接目录到终端环境,然后启动,这种方式可以为不同的程序配置不同的加载路径exportLD_LIBRARY_PA......
  • Rpmbuild原码打包成rpm包
    RPM有五种基本的操作功能:安装、卸载、升级、查询和验证。linux软件包分为两大类:(1)二进制类包,包括rpm安装包(一般分为i386和x86等几种)(2)源码类包,源码包和开发包应该归位此类......
  • Java调用Linux命令(cd的处理)
    一、Java调用Linux系统的命令非常简单这是一个非常常用的调用方法示例:1publicStringexecuteLinuxCmd(Stringcmd){2System.out.println("gotcmd......
  • mysql 中的auto_increment自增值
    1.初始化自增值默认值是从1开始,在建表时使用“AUTO_INCREMENT=n”可以来指定一个自增的初始值,比如:CREATETABLEtest(idINTUNSIGNEDNOTNULLPRIMARYKEYAUTO_INCR......
  • 使用 DataX 实现 MySQL 数据的高效同步
    使用DataX实现MySQL数据的高效同步发布于2022-07-1816:07:19阅读 5590 本周赠书《性能之巅》第2版我们公司有个项目的数据量高达五千万,但是因为报表那......
  • mysql 授权远程访问
    进入mysql命令1.进入cd/usr/local/mysql/bin下执行./mysql-uroot-pInfosec@2020 (-p后面是数据库密码)2.usemysql;3.updateusersethost='%'whereuser='r......
  • MySQL最大建议行数2000W?老司机做了个实验……
      一、背景 作为在后端圈开车的多年老司机,是不是经常听到过,“mysql单表最好不要超过2000w”,“单表超过2000w就要考虑数据迁移了”,“你这个表数据都马上要到20......
  • 通过xshell在linux上安装nginx1.12.0
    0)环境安装Nginx是C语言开发,建议在Linux上运行,当然,也可以安装Windows版本,本篇则使用CentOS7作为安装环境。 0.1gcc安装安装nginx需要先将官网下载的源码进......
  • mysql索引简谈
                           mysql索引简谈 一、什么是索引就好比我们在看一本书的时候,有目录的话,我们可以快速定位到想看......
  • 【MySQL】谈谈锁的类型
    前言MySQL中的锁分为表锁以及行锁,从字面意思就可以得知,表锁是对一整张表进行加锁,而行锁是针对于特定的行。在Server层面,提供了表锁的实现,而行锁则由存储引擎实现。Innodb......