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