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

MySQL练习

将安装包下载并上传

方法一

步骤

创建组与用户

[root@localhost ~]# groupadd mysql
[root@localhost ~]# useradd -r -g mysql -s /bin/false mysql

解压安装包

[root@localhost ~]# tar xf  mysql-8.0.36-linux-glibc2.28-x86_64.tar.xz -C /usr/local/

软连接

[root@localhost ~]# ln -sv mysql-8.0.36-linux-glibc2.28-x86_64 /usr/local/mysql
'/usr/local/mysql' -> 'mysql-8.0.36-linux-glibc2.28-x86_64'

初始化

[root@localhost ~]# /usr/local/mysql/bin/mysqld --initialize --user=mysql --datadir=/usr/local/mysql/data
2025-02-04T08:37:33.610736Z 0 [System] [MY-013169] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.36) initializing of server in progress as process 2086
2025-02-04T08:37:33.625049Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2025-02-04T08:37:34.296122Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2025-02-04T08:37:35.362477Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: wYiSf83tCu*2

配置文件

[root@localhost ~]# mkdir /var/log/mysql

[root@openEuler-1 ~]# vim /etc/my.cnf
 
basedir=/usr/local/mysql/
datadir=/usr/local/mysql/data/
socket=/tmp/mysql.sock
log-error=/usr/local/mysql/data/mysqld.log
pid-file=/usr/local/mysql/data/mysqld.pid

增加权限

[root@localhost ~]# chown -R mysql.mysql /usr/local/mysql/*

添加系统服务

[root@localhost ~]# cd /usr/local/mysql/
[root@localhost mysql]# ls
bin  data  docs  include  lib  LICENSE  man  README  share  support-files
[root@localhost mysql]# cd support-files/
[root@localhost support-files]# ls
mysqld_multi.server  mysql-log-rotate  mysql.server
[root@localhost support-files]# vim mysql.server
[root@localhost support-files]# cp mysql.server /etc/init.d/mysqld
[root@localhost support-files]# ll /etc/rc.d/rc3.d/
total 0
[root@localhost support-files]# chkconfig --add mysqld
[root@localhost support-files]# ll /etc/rc.d/rc3.d/
total 0
lrwxrwxrwx 1 root root 16 Feb  4 16:57 S64mysqld -> ../init.d/mysqld
[root@localhost support-files]# chkconfig mysqld on
[root@localhost 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

启动服务

[root@localhost support-files]# systemctl start mysqld

登录MySQL

[root@localhost support-files]# /usr/local/mysql/bin/mysql -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.36
 
Copyright (c) 2000, 2024, 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.00 sec)

配置环境变量

[root@localhost support-files] vim /etc/profile.d/mysql.sh
 
export PATH=$PATH:/usr/local/mysql/bin
 
[root@localhost support-files] source /etc/profile.d/mysql.sh



[root@localhost support-files]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 8.0.36 MySQL Community Server - GPL
 
Copyright (c) 2000, 2024, 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>

删除系统服务

[root@localhost support-files]# chkconfig mysqld off
[root@localhost 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:off   3:off   4:off   5:off   6:off

删除文件


[root@localhost support-files]# chkconfig --del mysqld
[root@localhost support-files]# ll /etc/init.d/
total 36
-rw-r--r--. 1 root root 18229 Aug 24  2022 functions
-rwxr-xr-x  1 root root 10576 Feb  4 16:55 mysqld
-rw-r--r--. 1 root root  1161 Jun 22  2024 README
[root@localhost support-files]# rm -f /etc/init.d/mysqld

方法二

配置文件

[root@localhost support-files]# vim /usr/lib/systemd/system/mysqld.service


Description=MySQL 8.0 database server
After=syslog.target
After=network.target
 
[Service]
Type=notify
User=mysql
Group=mysql
 
ExecStart=/usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
ExecStop=/usr/local/mysql/bin/mysqladmin -uroot shutdown
 
 
 
TimeoutSec=300
PrivateTmp=true
 
Restart=on-failure
 
RestartPreventExitStatus=1
LimitNOFILE = 10000
 
[Install]
WantedBy=muli-user.target

加载设置

[root@localhost support-files]# systemctl daemon-reload

相关文章:

  • AI人工智能机器学习之降维和数据压缩
  • 基于W2605C语音识别合成芯片的智能语音交互闹钟方案-AI对话享受智能生活
  • lvgl运行机制分析
  • 车载以太网-基于linux的ICMP协议
  • 决策树(Decision Tree)详细解释(带示例)
  • 精神分裂症患者GAF评分的可视化分析|使用集成学习模型 LightGBM
  • Linux操作系统:基于 Linux 的工业机器人项目设计与实现
  • 【uniapp】在UniApp中实现持久化存储:安卓--生成写入数据为jsontxt
  • python环境打包2 pytorch和cuda的安装逻辑
  • 鸿蒙兼容Mapbox地图应用测试
  • 解决npm run dev报错
  • STM32 微控制器库RCC_OscInitTypeDef结构参数介绍
  • 精通 Fiddler:Web 调试利器的深度探索
  • RabbitMQ系列(七)基本概念之Channel
  • 双臂机器人的动力学建模
  • 算法day2 dfs搜索2题
  • 关于CAN光纤联网在电池簇电池集装箱灭火系统中的应用的文章:
  • 2025网络安全工程师好就业吗?网络安全工程师就业前景如何?
  • DPVS-6:软件框架简介
  • 自用的vim脚本
  • 自己做网站视频教程/软文推广有哪些
  • 英文网站公司/外贸seo优化公司
  • 企业网站包括哪些/百度霸屏推广靠谱吗
  • 外包做网站要十几万/新闻稿在线
  • 怎么建设网站后台/南宁百度推广代理商
  • 建设返利网站/谷歌seo软件