当前位置: 首页 > article >正文

安装MySQL在Linux环境下

1,上传源码

2,创建用户组

[root@openEuler-1 ~]# groupadd mysql

3,创建用户来运行数据库

[root@openEuler-1 ~]# useradd -r -g mysql -s /bin/false mysql

4,将压缩文件解压到/usr/local/中

[root@openEuler-1 ~]# tar xf mysql-8.0.36-linux-glibc2.12-x86_64.tar.xz -C /usr/local/
[root@openEuler-1 ~]# ll /usr/local/
total 44
drwxr-xr-x. 2 root root 4096 May 25  2024 bin
drwxr-xr-x. 2 root root 4096 May 25  2024 etc
drwxr-xr-x. 2 root root 4096 May 25  2024 games
drwxr-xr-x. 2 root root 4096 May 25  2024 include
drwxr-xr-x. 2 root root 4096 May 25  2024 lib
drwxr-xr-x. 3 root root 4096 Jan 10 19:30 lib64
drwxr-xr-x. 2 root root 4096 May 25  2024 libexec
drwxr-xr-x  9 root root 4096 Jan 14 21:06 mysql-8.0.36-linux-glibc2.12-x86_64
drwxr-xr-x. 2 root root 4096 May 25  2024 sbin
drwxr-xr-x. 5 root root 4096 Jan 10 19:30 share
drwxr-xr-x. 2 root root 4096 May 25  2024 src

5,进行软连接
[root@openEuler-1 ~]# ln -sv /usr/local/mysql-8.0.36-linux-glibc2.12-x86_64/ /usr/local/mysql
'/usr/local/mysql' -> '/usr/local/mysql-8.0.36-linux-glibc2.12-x86_64/'
[root@openEuler-1 ~]# ll /usr/local/mysql/data/
total 0

6,进行初始化,这里需要记住登录密码
[root@openEuler-1 ~]# /usr/local/mysql/bin/mysqld --initialize --user=mysql --datadir=/usr/local/mysql/data
2025-01-14T13:14:37.200025Z 0 [System] [MY-013169] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.36) initializing of server in progress as process 2113
2025-01-14T13:14:37.208018Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2025-01-14T13:14:37.750996Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2025-01-14T13:14:39.967122Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: TJZdqB_ue0U8

7,创建配置文件
[root@openEuler-1 ~]# vim /etc/my.cnf

[root@openEuler-1 ~]# mkdir /var/log/mysql
[root@openEuler-1 ~]# chown -R mysql.mysql /usr/local/mysql/*
[root@openEuler-1 ~]# cd /usr/local/mysql
[root@openEuler-1 mysql]# ls
[root@openEuler-1 mysql]# cd support-files/
[root@openEuler-1 support-files]# ls
mysqld_multi.server  mysql-log-rotate  mysql.server

8,将mysql.server 移动到/etc/init.d/mysqld

[root@openEuler-1 support-files]# cp mysql.server /etc/init.d/mysqld
[root@openEuler-1 support-files]# ll /etc/init.d/mysql
mysqld        mysql.server
[root@openEuler-1 support-files]# ll /etc/init.d/mysqld
-rwxr-xr-x 1 root root 10576 Jan 14 21:29 /etc/init.d/mysqld

9,查看 /etc/rc.d/rc3.d/ 目录下的文件和目录的详细信息,包括文件类型、权限、所有者、所属组、大小、修改时间和文件名等。在Linux系统中, /etc/rc.d/rc3.d/ 目录通常用于存放系统在运行级别3(多用户模式)下启动的服务脚本的链接。

[root@openEuler-1 support-files]# ll /etc/rc.d/rc3.d/
total 0

10,将MySQL添加到系统服务列表中
[root@openEuler-1 support-files]# chkconfig --add mysqld
[root@openEuler-1 support-files]# ll /etc/rc.d/rc3.d/
total 0
lrwxrwxrwx 1 root root 16 Jan 14 21:30 S64mysqld -> ../init.d/mysqld

11,开机自启动
[root@openEuler-1 support-files]# chkconfig mysqld on

12,列出mysqld服务在各个运行级别下的启动状态
[root@openEuler-1 support-files]# chkconfig --list mysqld

Note: This output shows SysV services only and does not include native
      systemd services. SysV configuration data might be overridden by native
      systemd configuration.

      If you want to list systemd services use 'systemctl list-unit-files'.
      To see services enabled on particular target use
      'systemctl list-dependencies [target]'.

mysqld          0:off   1:off   2:on    3:on    4:on    5:on    6:off

13,启动服务

[root@openEuler-1 ~]# systemctl start mysqld

14,查看服务状态
[root@openEuler-1 ~]# systemctl status mysqld
● mysqld.service - LSB: start and stop MySQL
     Loaded: loaded (/etc/rc.d/init.d/mysqld; generated)
     Active: active (running) since Tue 2025-01-14 21:51:11 CST; 16s ago
       Docs: man:systemd-sysv-generator(8)
    Process: 3260 ExecStart=/etc/rc.d/init.d/mysqld start (code=exited, status=0/SUCCESS)
[root@openEuler-1 support-files]# yum install ncurses-compat-libs

15,登录mysql
[root@openEuler-1 support-files]# /usr/local/mysql/bin/mysql -uroot -p

16,修改密码
mysql> alter user root@localhost identified by '123456';

mysql> \q

17,编写脚本,使登录不需要输入完整路径
[root@openEuler-1 support-files]# vim /etc/profile.d/mysql.sh

18,使定义的环境变量生效
[root@openEuler-1 support-files]# source /etc/profile.d/mysql.sh

19,测试登录
[root@openEuler-1 support-files]# mysql -uroot -p123456


 


http://www.kler.cn/a/503344.html

相关文章:

  • Qiskit快速编程探索(进阶篇)
  • PCB印刷电路板快速上手04电容元件
  • 计算机网络速成
  • 基于springboot+vue的洪涝灾害应急信息管理系统设计与实现
  • JSON.stringify(res,null,2)的含义
  • pandas与sql对应关系【帮助sql使用者快速上手pandas】
  • 深入解析Alertmanager启动命令行参数及其作用
  • zookeeper-配置
  • [Git] 深入理解 Git 的客户端与服务器角色
  • 通信网络安全分层及关键技术解决
  • 深圳观澜森林公园及五指耙森林公园边坡自动化监测
  • C# HslCommunication库
  • java 组合框
  • Flutter(Dart)的集合类型List、Set 和 Map
  • open3d+opencv实现矩形框裁剪点云操作(C++)
  • 【动态规划-矩阵】5.下降路径最小和
  • 蓝牙的UUID(Universally Unique Identifier,通用唯一识别码)
  • 探索深度学习:开启智能新时代
  • 信号量机制之苹果-橘子问题
  • 【汇编】x86汇编编程寄存器资源心中有数
  • vulnhub靶场【IA系列】之Tornado
  • 地瓜机器人RDK Studio使用入门教程
  • 《自动驾驶与机器人中的SLAM技术》ch10:自动驾驶车辆的实时定位系统
  • 解决 vxe-table 的下拉框、日期选择等组件被 element-plus element-ui 弹窗遮挡问题 z-index
  • es 3期 第23节-运用Pipeline实现二转聚合统计
  • 【AI日记】25.01.14