01-Linux安装MySQL

CentOS7 安装MySQL 8.0.28

一、下载MySQL安装包
下载地址:https://downloads.mysql.com/archives/community/
在这里插入图片描述
下载完成后,上传到对应的Linux服务器上面。
二、解压安装MySQL
Step1 进入到上传上来的mysql安装包的路径里面

[root@localhost files]# ll
total 823252
-rw-r--r--. 1 root root 843008000 Jan  9 20:0ql-8.0.28-1.el7.x86_64.rpm-bundle.tar

可以查看到对应的mysql文件。
Step2 解压安装包

[root@localhost files]# tar -xvf mysql-8.0.287.x86_64.rpm-bundle.tar 
mysql-community-client-8.0.28-1.el7.x86_64.rp
mysql-community-client-plugins-8.0.28-1.el7.x.rpm
mysql-community-common-8.0.28-1.el7.x86_64.rp
mysql-community-devel-8.0.28-1.el7.x86_64.rpm
mysql-community-embedded-compat-8.0.28-1.el7.4.rpm
mysql-community-icu-data-files-8.0.28-1.el7.x.rpm
mysql-community-libs-8.0.28-1.el7.x86_64.rpm
mysql-community-libs-compat-8.0.28-1.el7.x86_m
mysql-community-server-8.0.28-1.el7.x86_64.rp
mysql-community-test-8.0.28-1.el7.x86_64.rpm

Step3 卸载掉系统自带的mariadb

[root@localhost files]# rpm -qa|grep mariadb
mariadb-libs-5.5.68-1.el7.x86_64
[root@localhost files]# rpm -e --nodeps mariab-libs
[root@localhost files]# rpm -qa|grep mariadb

Step4 安装MySQL
一定要注意这里需要按照顺序去安装

[root@localhost files]# rpm -ivh mysql-communty-common-8.0.28-1.el7.x86_64.rpm 
warning: mysql-community-common-8.0.28-1.el7.86_64.rpm: Header V4 RSA/SHA256 Signature, ke ID 3a79bd29: NOKEY
Preparing...                          ################################ [100%]
Updating / installing...
   1:mysql-community-common-8.0.28-1.e################################ [100%]
   
[root@localhost files]# rpm -ivh mysql-communty-client-plugins-8.0.28-1.el7.x86_64.rpm 
warning: mysql-community-client-plugins-8.0.2-1.el7.x86_64.rpm: Header V4 RSA/SHA256 Signaure, key ID 3a79bd29: NOKEY
Preparing...                          ################################ [100%]
Updating / installing...
   1:mysql-community-client-plugins-8.################################ [100%]
   
[root@localhost files]# rpm -ivh mysql-communty-libs-8.0.28-1.el7.x86_64.rpm 
warning: mysql-community-libs-8.0.28-1.el7.x8_64.rpm: Header V4 RSA/SHA256 Signature, key D 3a79bd29: NOKEY
Preparing...                          ################################ [100%]
Updating / installing...
   1:mysql-community-libs-8.0.28-1.el7################################ [100%]
   
[root@localhost files]# rpm -ivh mysql-communty-client-8.0.28-1.el7.x86_64.rpm 
warning: mysql-community-client-8.0.28-1.el7.86_64.rpm: Header V4 RSA/SHA256 Signature, ke ID 3a79bd29: NOKEY
Preparing...                          ################################ [100%]
Updating / installing...
   1:mysql-community-client-8.0.28-1.e################################ [100%]
   
[root@localhost files]# rpm -ivh mysql-communty-icu-data-files-8.0.28-1.el7.x86_64.rpm 
warning: mysql-community-icu-data-files-8.0.2-1.el7.x86_64.rpm: Header V4 RSA/SHA256 Signaure, key ID 3a79bd29: NOKEY
Preparing...                          ################################ [100%]
Updating / installing...
   1:mysql-community-icu-data-files-8.################################ [100%]
   
[root@localhost files]# rpm -ivh mysql-communty-server-8.0.28-1.el7.x86_64.rpm 
warning: mysql-community-server-8.0.28-1.el7.86_64.rpm: Header V4 RSA/SHA256 Signature, ke ID 3a79bd29: NOKEY
Preparing...                          ################################ [100%]
Updating / installing...
   1:mysql-community-server-8.0.28-1.e############################## [100%]%)

Step5 初始化MySQL

[root@localhost files]# mysqld --initialize -nsole
[root@localhost files]# chown -R mysql:mysql r/lib/mysql/
[root@localhost files]# systemctl start mysql
[root@localhost files]# cat /var/log/mysqld.l|grep localhost
2024-01-09T12:23:10.540708Z 6 [Note] [MY-0104 [Server] A temporary password is generated froot@localhost: n0Drlq6D3o&U

这里的 n0Drlq6D3o&U 就是初始化的MySQL登录密码。
Step6 登录MySQL

# 这样子会暴露密码出来不安全,mysql建议使用第二种
[root@localhost files]# mysql -uroot -pn0Drlqo&U
[1] 6881
-bash: U: command not found
[root@localhost files]# mysql: [Warning] Usin password on the command line interface can bnsecure.

# 第二种方法
[root@localhost files]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end w ; or \g.
Your MySQL connection id is 9
Server version: 8.0.28

三、密码修改
Step1 登录

# 第二种方法
[root@localhost files]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end w ; or \g.
Your MySQL connection id is 9
Server version: 8.0.28

Step2 修改root用户的登录密码

mysql> alter user 'root'@'localhost' identifiby 'newPassword';
Query OK, 0 rows affected (0.02 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.02 sec)

Step3 创建用户

mysql> create user 'username'@'localhost' identid by 'mysql';
Query OK, 0 rows affected (0.08 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.02 sec)

mysql> select user from mysql.user;
+------------------+
| user             |
+------------------+
| mysql            |
| mysql.infoschema |
| mysql.session    |
| mysql.sys        |
| root             |
+------------------+

# 授权,mysql8授权命令为
grant priv_type on table to 'xxxx'@'xxx';

# 此处针对用户赋予了针对全部表的所有权限。
mysql> grant all privileges on *.* to 'xxx'@'xxx';

Step4 用户开通外界访问

mysql> rename user 'kylin'@'localhost' to 'kylin'@'%';
Query OK, 0 rows affected (0.02 sec)

mysql> rename user 'root'@'localhost' to 'root'@'%';
Query OK, 0 rows affected (0.05 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)

mysql> select user,host from mysql.user;
+------------------+-----------+
| user             | host      |
+------------------+-----------+
| kylin            | %         |
| root             | %         |
| mysql.infoschema | localhost |
| mysql.session    | localhost |
| mysql.sys        | localhost |
+------------------+-----------+
5 rows in set (0.01 sec)

Step5 开通防火墙

[root@localhost files]# firewall-cmd --list-ports
6379/tcp 6380/tcp 
# 添加 3306端口
[root@localhost files]# firewall-cmd --zone=pic --add-port=3306/tcp --permanent
[root@localhost files]# firewall-cmd --reload
success
[root@localhost files]# firewall-cmd --list-ports
6379/tcp 6380/tcp 3306/tcp

Step6 外界访问
我这里使用的是DataGrip连接数据库。
在这里插入图片描述

  • 7
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值