Linux Centos安装Mysql

概述

安装mysql8,暂不指定数据目录。

检查是否安装mysql

[root@localhost ~]# yum list installed mysql
错误:没有匹配的软件包可以列出
[root@localhost ~]#

下载tar.xz包

  • 如果没有wget(wget是linux中的一个下载文件的工具),先安装wget
yum install -y wget
  1. 先查看glic的版本
[root@localhost ~]# yum list installed glibc
已安装的软件包
glibc.x86_64                                       2.28-42.el8.1                                        @anaconda
[root@localhost ~]#
  1. 我的版本比较高,所以选择下面mysql版本
    在这里插入图片描述
  2. 复制现在链接
    在这里插入图片描述https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.25-linux-glibc2.17-x86_64-minimal.tar.xz
  3. 开始下载
[root@localhost ~]# wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.25-linux-glibc2.17-x86_64-minimal.tar.xz
--2021-06-27 18:05:08--  https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.25-linux-glibc2.17-x86_64-minimal.tar.xz
正在解析主机 dev.mysql.com (dev.mysql.com)... 137.254.60.11
正在连接 dev.mysql.com (dev.mysql.com)|137.254.60.11|:443... 已连接。
已发出 HTTP 请求,正在等待回应... 302 Found
位置:https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.25-linux-glibc2.17-x86_64-minimal.tar.xz [跟随至新的 URL]
--2021-06-27 18:05:09--  https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.25-linux-glibc2.17-x86_64-minimal.tar.xz
正在解析主机 cdn.mysql.com (cdn.mysql.com)... 184.26.157.95
正在连接 cdn.mysql.com (cdn.mysql.com)|184.26.157.95|:443... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:51235496 (49M) [text/plain]
正在保存至: “mysql-8.0.25-linux-glibc2.17-x86_64-minimal.tar.xz”

mysql-8.0.25-linux-glibc2.17 100%[===========================================>]  48.86M  5.71MB/s  用时 9.2s

2021-06-27 18:05:19 (5.30 MB/s) - 已保存 “mysql-8.0.25-linux-glibc2.17-x86_64-minimal.tar.xz” [51235496/51235496])

[root@localhost ~]#
  1. 移动mysql并解压
[root@localhost ~]# tar -xvf mysql-8.0.25-linux-glibc2.17-x86_64-minimal.tar.xz
[root@localhost ~]# mv mysql-8.0.25-linux-glibc2.17-x86_64 /usr/local/mysql
  1. 创建mysql用户并分配权限
# 创建mysql组
[root@localhost]# groupadd mysql
# 创建mysql用户,并指定mysql用户组
[root@localhost]# useradd -g mysql mysql
# 将目录 mysql 的拥有者设为 mysql,群体的使用者mysql
[root@localhost]# chown mysql:mysql /usr/local/mysql
# 分配用户权限
[root@localhost]# chmod 750 /usr/local/mysql/
[root@localhost l]# ll /usr/local/ | grep mysql
drwxr-x---. 3 mysql mysql 57 6月  27 18:13 mysql

初始化数据目录

  • windows上安装没经历过初始化数据目录,只是会有一个初始化密码需要更改
    在这里插入图片描述
    所以我们是必须初始化数据目录的。
  • 初始化数据目录之前记得安装一下libaio库。
    在这里插入图片描述
# 已经安装过就不需要安装了
[root@localhost mysql]# yum list intalled libaio
上次元数据过期检查:1:23:42 前,执行于 2021年06月27日 星期日 17时10分34秒。
已安装的软件包
libaio.x86_64                                      0.3.110-12.el8                                       @anaconda
可安装的软件包
libaio.i686                                        0.3.112-1.el8                                        BaseOS
libaio.x86_64                                      0.3.112-1.el8                                        BaseOS
[root@localhost mysql]#
  • 初始化并指定据库目录和文件由mysql登录帐户拥有。
[root@localhost mysql]# bin/mysqld --initialize --user=mysql
2021-06-27T10:37:15.786813Z 0 [System] [MY-013169] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.25) initializing of server in progress as process 3504
2021-06-27T10:37:15.796813Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2021-06-27T10:37:17.119218Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
# TfAgK4g.5gZC  就是临时密码
2021-06-27T10:37:19.096487Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: TfAgK4g.5gZC
[root@localhost mysql]#

root是登陆用户,TfAgK4g.5gZC是初始化密码

测试mysql服务器

  • 启动Mysql服务器(以Mysql用户的身份启动)
[root@localhost mysql]# bin/mysqld_safe --user=mysql &
[1] 3603
[root@localhost opt]# ps -ef|grep mysql
root       3603   2655  0 18:42 pts/0    00:00:00 /bin/sh bin/mysqld_safe --user=mysql
mysql      3685   3603  0 18:42 pts/0    00:00:01 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=localhost.centos8.err --pid-file=localhost.centos8.pid
root       3747   3018  0 18:45 pts/1    00:00:00 grep --color=auto mysql
  • 登陆服务器
    报错直接yum install libncurses* 就可以了。
[root@localhost mysql]# bin/mysql -u root -p
bin/mysql: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory
[root@localhost mysql]# yum install libncurses*
上次元数据过期检查:1:42:17 前,执行于 2021年06月27日 星期日 17时10分34秒。
Package ncurses-libs-6.1-7.20180224.el8.x86_64 is already installed.
依赖关系解决。
=================================================================================================================
 软件包                           架构                版本                             仓库                 大小
=================================================================================================================
Installing:
 ncurses-c++-libs                 x86_64              6.1-7.20180224.el8               BaseOS               58 k
 ncurses-compat-libs              x86_64              6.1-7.20180224.el8               BaseOS              331 k

事务概要
=================================================================================================================
安装  2 软件包

总下载:389 k
安装大小:1.3 M
确定吗?[y/N]: y
下载软件包:
(1/2): ncurses-c++-libs-6.1-7.20180224.el8.x86_64.rpm                             50 kB/s |  58 kB     00:01
(2/2): ncurses-compat-libs-6.1-7.20180224.el8.x86_64.rpm                         248 kB/s | 331 kB     00:01
-----------------------------------------------------------------------------------------------------------------
总计                                                                             135 kB/s | 389 kB     00:02
运行事务检查
事务检查成功。
运行事务测试
事务测试成功。
运行事务
  准备中      :                                                                                              1/1
  Installing  : ncurses-compat-libs-6.1-7.20180224.el8.x86_64                                                1/2
  Installing  : ncurses-c++-libs-6.1-7.20180224.el8.x86_64                                                   2/2
  运行脚本    : ncurses-c++-libs-6.1-7.20180224.el8.x86_64                                                   2/2
  验证        : ncurses-c++-libs-6.1-7.20180224.el8.x86_64                                                   1/2
  验证        : ncurses-compat-libs-6.1-7.20180224.el8.x86_64                                                2/2

已安装:
  ncurses-c++-libs-6.1-7.20180224.el8.x86_64            ncurses-compat-libs-6.1-7.20180224.el8.x86_64

完毕!
# 密码用初始化密码即可
[root@localhost mysql]# bin/mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.25

Copyright (c) 2000, 2021, 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>
  • 修改登陆密码
mysql> alter user 'root'@'localhost' identified by '123456';
Query OK, 0 rows affected (0.02 sec)
mysql>
mysql>  FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.01 sec)
  • 退出mysql,关闭mysql服务,再次启动登陆
    注意使用新密码:123456登陆
[root@localhost mysql]# bin/mysqladmin -u root -p shutdown
Enter password:
2021-06-27T11:09:05.528904Z mysqld_safe mysqld from pid file /usr/local/mysql/data/localhost.centos8.pid ended
[1]+  已完成               bin/mysqld_safe --user=mysql
[root@localhost mysql]#
[root@localhost mysql]#
[root@localhost mysql]# ps -ef|grep mysql
root       4034   2655  0 19:09 pts/0    00:00:00 grep --color=auto mysql
[root@localhost mysql]# bin/mysqld --user=mysql &
[1] 4044
[root@localhost mysql]# 2021-06-27T11:10:22.449861Z 0 [System] [MY-010116] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.25) starting as process 4044
2021-06-27T11:10:22.464294Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2021-06-27T11:10:22.608140Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2021-06-27T11:10:22.694587Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '::' port: 33060, socket: /tmp/mysqlx.sock
2021-06-27T11:10:22.770342Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2021-06-27T11:10:22.770492Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
2021-06-27T11:10:22.785451Z 0 [System] [MY-010931] [Server] /usr/local/mysql/bin/mysqld: ready for connections. Version: '8.0.25'  socket: '/tmp/mysql.sock'  port: 3306  MySQL Community Server - GPL.

[root@localhost mysql]#
[root@localhost mysql]#
[root@localhost mysql]# bin/mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.25 MySQL Community Server - GPL

Copyright (c) 2000, 2021, 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>
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.01 sec)

设置数据库用ip地址访问

mysql> select @@VERSION;
+-----------+
| @@VERSION |
+-----------+
| 8.0.25    |
+-----------+
1 row in set (0.00 sec)

mysql> grant all privileges on *.* to 'root'@'%' with grant option;
ERROR 1410 (42000): You are not allowed to create a user with GRANT
mysql> create user 'root'@'%' identified by  '123456';
ERROR 1396 (HY000): Operation CREATE USER failed for 'root'@'%'
mysql> select User,Host from user;
+------------------+-----------+
| User             | Host      |
+------------------+-----------+
| root             | %         |
| mysql.infoschema | localhost |
| mysql.session    | localhost |
| mysql.sys        | localhost |
+------------------+-----------+
4 rows in set (0.00 sec)

mysql>
mysql>
mysql>
mysql>
# 高版本需要使用下面授权语句而不是:"grant all privileges on *.* to "root"@"%" identified by "xxxxx";"
mysql> grant all privileges on *.* to 'root'@'%' with grant option;
Query OK, 0 rows affected (0.01 sec)

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

测试

在这里插入图片描述

参考

mysql安装
mysql ip地址访问设置

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

融极

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值