• Centos7离线安装Mysql8(rpm安装)


    1. 下载:

            官网下载: MySQL :: Download MySQL Community Server

    2. 解压

    将下载好的tar文件放到centos中,目录文件夹名称自定义,解压后得到:

    1. [root@localhost mysql]# tar -xvf mysql-8.0.26-1.el7.x86_64.rpm-bundle.tar
    2. mysql-community-client-8.0.26-1.el7.x86_64.rpm
    3. mysql-community-client-plugins-8.0.26-1.el7.x86_64.rpm
    4. mysql-community-common-8.0.26-1.el7.x86_64.rpm
    5. mysql-community-devel-8.0.26-1.el7.x86_64.rpm
    6. mysql-community-embedded-compat-8.0.26-1.el7.x86_64.rpm
    7. mysql-community-libs-8.0.26-1.el7.x86_64.rpm
    8. mysql-community-libs-compat-8.0.26-1.el7.x86_64.rpm
    9. mysql-community-server-8.0.26-1.el7.x86_64.rpm
    10. mysql-community-test-8.0.26-1.el7.x86_64.rpm

    这里我们只需要client和server,其他不需要安装

    将centos7会自带的mariadb删除

    rpm -e --nodeps mariadb-libs
    

    3. 安装

    按照以下顺序执行:

    1. rpm -ivh mysql-community-common-8.0.26-1.el7.x86_64.rpm --force --nodeps
    2. rpm -ivh mysql-community-libs-8.0.26-1.el7.x86_64.rpm --force --nodeps
    3. rpm -ivh mysql-community-client-8.0.26-1.el7.x86_64.rpm --force --nodeps
    4. rpm -ivh mysql-community-server-8.0.26-1.el7.x86_64.rpm --force --nodeps

    这里需要注意的是,如果不加 --force --nodeps 可能会报错,这是由于yum安装了旧版本的GPG keys造成的。

            依赖检测失败: mariadb-libs 被 mysql-community-libs-8.0.23-1.el7.x86_64 取代...

    安装完后默认目录为:/var/lib/mysql  ,需要设置权限

    chmod -R 777 /var/lib/mysql

    初始化mysql

    mysqld --initialize

     获取默认密码

    cat /var/log/mysqld.log
    1. [root@localhost lib]# cat /var/log/mysqld.log
    2. 2022-12-03T17:30:00.122696Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.26) initializing of server in progress as process 6579
    3. 2022-12-03T17:30:00.265192Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
    4. 2022-12-03T17:30:03.100689Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
    5. 2022-12-03T17:30:08.936428Z 0 [Warning] [MY-013746] [Server] A deprecated TLS version TLSv1 is enabled for channel mysql_main
    6. 2022-12-03T17:30:08.947078Z 0 [Warning] [MY-013746] [Server] A deprecated TLS version TLSv1.1 is enabled for channel mysql_main
    7. 2022-12-03T17:30:09.044202Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: BrFwhHdcN0)p

    日志最后的 BrFwhHdcN0)p 为默认密码。

    如果没启动mysql服务,则启动一下

    1. [root@localhost lib]# service mysqld start
    2. Redirecting to /bin/systemctl start mysqld.service
    3. [root@localhost lib]# service mysqld status
    4. Redirecting to /bin/systemctl status mysqld.service
    5. ● mysqld.service - MySQL Server
    6. Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
    7. Active: active (running) since 日 2022-12-04 01:40:35 CST; 17s ago
    8. Docs: man:mysqld(8)
    9. http://dev.mysql.com/doc/refman/en/using-systemd.html
    10. Process: 18920 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
    11. Main PID: 19362 (mysqld)
    12. Status: "Server is operational"
    13. Tasks: 38
    14. CGroup: /system.slice/mysqld.service
    15. └─19362 /usr/sbin/mysqld
    16. 1204 01:40:16 localhost.localdomain systemd[1]: Starting MySQL Server...
    17. 1204 01:40:35 localhost.localdomain systemd[1]: Started MySQL Server.

    重新设置密码:

    进入msql命令编辑器, 密码为刚才日志里的密码:BrFwhHdcN0)p

    1. [root@localhost lib]# mysql -uroot -p
    2. Enter password:

    这里需要注意:新的密码一定要符合mysql8的规范,不然更新不了,或者是更新了后面有问题! 

    1. mysql> alter user 'root'@'localhost' identified by 'Mhf1997=qfl';
    2. Query OK, 0 rows affected (0.10 sec)

    设置Navicat远程连接:

    1. mysql> use mysql
    2. Reading table information for completion of table and column names
    3. You can turn off this feature to get a quicker startup with -A
    4. Database changed
    5. mysql>

    修改 root 的 host 为 % 

    1. mysql> update user set host='%' where user='root';
    2. Query OK, 1 row affected (0.02 sec)
    3. Rows matched: 1 Changed: 1 Warnings: 0

     执行俩次:GRANT ALL ON *.* TO 'root'@'%';

    1. mysql> GRANT ALL ON *.* TO 'root'@'%';
    2. ERROR 1410 (42000): You are not allowed to create a user with GRANT
    3. mysql> GRANT ALL ON *.* TO 'root'@'%';
    4. Query OK, 0 rows affected (0.03 sec)

    设置一下立即生效:

    1. mysql> FLUSH PRIVILEGES;
    2. Query OK, 0 rows affected (0.03 sec)

    重启mysql服务

    service mysqld restart

    这样就可以使用navicat远程连接了!

    补充知识: 

    linux操作mysql基本命令

    1. service mysqld status #查看mysql状态
    2. service mysqld stop #关闭
    3. service mysqld start #启动
    4. service mysqld restart #重启

    使用rpm安装mysql的默认目录:
    数据库目录             /var/lib/mysql/
    配置文件                 /usr/share/mysql(mysql.server命令及配置文件)
    相关命令                 /usr/bin(mysqladmin mysqldump等命令)
    启动脚本                 /etc/rc.d/init.d/(启动脚本文件mysql的目录) 

  • 相关阅读:
    5款推荐给手残党的AI代码提示,带你健步如飞
    切面Aspect + 策略模式实现待办提醒功能
    layui--table里使用switch
    SQL语句常见分类
    微信小程序post请求数据传送不出去
    SpringBoot 场景开发多面手成长手册
    计算机毕业设计JavaH5醉美南湾湖网站设计(源码+系统+mysql数据库+lw文档)
    单片机之瑞萨RL78定时计数器
    Arrays.asList():使用指南
    数智未来 持续创新 | 易趋受邀出席CIAS 2022中国数智汽车峰会
  • 原文地址:https://blog.csdn.net/m0_47743175/article/details/128163779