实训day20

nginx代理mysql环境
1、centos7 中安装 mysql 8.x
(1)下载安装包
wget https://downloads.mysql.com/archives/get/p/23/file/mysql-8.0.33-1.el7.x86_64.rpm-bundle.tar
(2)解压
tar -xf mysql-8.0.33-1.el7.x86_64.rpm-bundle.tar
(3)卸载maridb
yum -y remov mariadb-libs.x86_64
(4)下载net-tools
yum -y install net-tools
(5)下载rpm -ivh mysql-community-server-8.0.33-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-8.0.33-1.el7.x86_64.rpm
按要求一个一个依赖包下载,最后达到server软件包成功下载即可
(6)修改配置文件
vim /etc/my.cnf    //添加explicit_defaults_for_timestamp=true
rm -rf /var/lib/mysql/*

(7)初始化配置mysql
  mysqld --initialize
(8)启动mysql服务
systemctl start mysqld.service
(9)设置mysql开机自启
systemctl enable mysqld
(10)获得初始化密码
cat /var/log/mysqld.log | grep password
2024-08-02T02:04:03.141224Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: !iI-ht4hXM5,
(11)使用初始密码登陆
mysql -uroot -p
!iI-ht4hXM5,
(12)设置密码
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'Root@123456';
在mysql内将密码修改为Root@123456
(13)修改远程权限
create user 'root'@'%' identified with mysql_native_password by 'Root@123456';
grant all privileges on *.* to 'root'@'%' with grant option;
flush privileges;
2、mysql基础操作
(1)创建库
mysql> create datababse test charset utf8;
Query OK, 1 row affected, 1 warning (0.01 sec)
(2)查看库
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
| test               |
+--------------------+
5 rows in set (0.00 sec)
(3)删除库
mysql> drop database hh;
Query OK, 0 rows affected (0.04 sec)
(4)选择使用数据库
mysql> use test;
Database changed
(5)创建表
mysql> create table student(
     -> id int not null auto_increment,
     -> name varchar(20) not null,
     -> passwd varchar(20) not null,
     -> primary key (id)
     -> )comment = 'us';
Query OK, 0 rows affected (0.05 sec)
(6)查看表
mysql> show tables;
+----------------+
| Tables_in_test |
+----------------+
| student        |
| user           |
+----------------+
2 rows in set (0.01 sec)
(7)删除表
mysql> drop table student;
Query OK, 0 rows affected (0.03 sec)
(8)查看表结构
mysql> describe user;
+----------+-------------+------+-----+---------+----------------+
| Field    | Type        | Null | Key | Default | Extra          |
+----------+-------------+------+-----+---------+----------------+
| id       | int         | NO   | PRI | NULL    | auto_increment |
| username | varchar(45) | NO   | UNI | NULL    |                |
| password | varchar(45) | NO   |     | NULL    |                |
+----------+-------------+------+-----+---------+----------------+
3 rows in set (0.01 sec)
(9)查看创建表代码
mysql> show create table user;
+-------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table                                                                                                                                                                                                                                                            |
+-------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| user  | CREATE TABLE `user` (
   `id` int NOT NULL AUTO_INCREMENT,
   `username` varchar(45) NOT NULL,
   `password` varchar(45) NOT NULL,
   PRIMARY KEY (`id`),
   UNIQUE KEY `username_UNIQUE` (`username`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8mb3 COMMENT='us' |
+-------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
(10)新增列
mysql> alter table user add column realname varchar(20) null after password;
Query OK, 0 rows affected (0.01 sec)
Records: 0  Duplicates: 0  Warnings: 0
(11)修改列名
mysql> alter table user change column realname zsxm varchar(20) null default null;
Query OK, 0 rows affected (0.01 sec)
Records: 0  Duplicates: 0  Warnings: 0
(12)删除列
mysql> alter table user drop column zsxm;
Query OK, 0 rows affected (0.04 sec)
Records: 0  Duplicates: 0  Warnings: 0
(13)添加记录
mysql> insert into user(id,username,password) values(5,'小六','xiaoliu'),(6,'小七','xiaoqi');
Query OK, 2 rows affected (0.01 sec)
Records: 2  Duplicates: 0  Warnings: 0
(14)查看记录
mysql> select * from user;
+----+----------+----------+
| id | username | password |
+----+----------+----------+
|  1 | 张三     | 123      |
|  2 | 赵六     | zhaoliu  |
|  3 | 王五     | wangwu   |
|  4 | 李四     | lisi     |
|  5 | 小六     | xiaoliu  |
|  6 | 小七     | xiaoqi   |
+----+----------+----------+
6 rows in set (0.00 sec)
(15)删除记录
mysql> delete from user where username='张三';
(16)修改记录
mysql> update user set password=123 where username='小六';
Query OK, 1 row affected (0.01 sec)
Rows matched: 1  Changed: 1  Warnings: 0
3、mysql图示化操作软件使用
打开软件

点击加号-------------输入连接名字(随便)------------hostname(数据库主机的ip地址)----------------------ok

点击mysql02

输入密码

进入软件

如果出现以下页面:1、检查防火墙 2、查看是否为远程授权

以下是一个简单的C语言万年历的实训报告,供您参考: 一、实训目的 本次实训的主要目的是通过编写一个简单的C语言万年历程序,巩固C语言基本语法和编程思想,提高编程能力和解决问题的能力。 二、实训要求 1、能够使用C语言基本语法和控制语句编写程序。 2、能够使用数组来存储和操作数据。 3、能够使用函数来实现模块化编程。 4、能够使用指针来操作内存中的数据。 5、能够使用文件来读取和写入数据。 三、实训内容 1、程序功能 本程序实现了一个简单的万年历功能,可以通过输入年份和月份来显示该月的日历。 2、程序实现 以下是本程序的主要代码实现: ```c #include <stdio.h> // 判断是否为闰年 int is_leap_year(int year) { if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) { return 1; } else { return 0; } } // 获取某个月份的总天数 int get_days(int year, int month) { int days[] = {31, 28 + is_leap_year(year), 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; return days[month - 1]; } // 获取某个日期是星期几 int get_weekday(int year, int month, int day) { if (month == 1 || month == 2) { year--; month += 12; } int c = year / 100; int y = year % 100; int w = y + y / 4 + c / 4 - 2 * c + 26 * (month + 1) / 10 + day - 1; w = (w % 7 + 7) % 7; return w; } // 显示日历 void show_calendar(int year, int month) { int days = get_days(year, month); int weekday = get_weekday(year, month, 1); printf(" 日 一 二 三 四 五 六\n"); int i; for (i = 0; i < weekday; i++) { printf(" "); } for (i = 1; i <= days; i++) { printf("%2d ", i); if ((weekday + i) % 7 == 0) { printf("\n"); } } if ((weekday + days) % 7 != 0) { printf("\n"); } } int main() { int year, month; printf("请输入年份:"); scanf("%d", &year); printf("请输入月份:"); scanf("%d", &month); if (month < 1 || month > 12) { printf("月份输入错误!\n"); return 1; } printf(" %d年%d月\n", year, month); show_calendar(year, month); return 0; } ``` 四、实训总结 通过本次实训,我学会了如何使用C语言来编写一个简单的万年历程序,巩固了C语言基本语法和编程思想,加强了对函数、数组、指针、文件等概念和用法的理解,提高了编程能力和解决问题的能力。同时,我也意识到在编程过程中需要注重代码的规范、可读性和可维护性,这对于日后的开发工作非常重要。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值