2024.8.2(MySQL)

一、mysql

1、下载mysql软件包

root@mysql \~# yum -y install wget

root@mysql \~# wget https://downloads.mysql.com/archives/get/p/23/file/mysql-8.0.33-1.el7.x86_64.rpm-bundle.tar

2、解压

root@mysql \~# tar -xf mysql-8.0.33-1.el7.x86_64.rpm-bundle.tar

3、安装依赖包

root@mysql \~# rpm -e --nodeps mariadb-libs

root@mysql \~# rpm -ivh mysql-community-common-8.0.33-1.el7.x86_64.rpm
root@mysql \~# rpm -ivh mysql-community-client-plugins-8.0.33-1.el7.x86_64.rpm

root@mysql \~# rpm -ivh mysql-community-libs-8.0.33-1.el7.x86_64.rpm

root@mysql \~# rpm -ivh mysql-community-client-8.0.33-1.el7.x86_64.rpm
root@mysql \~# rpm -ivh mysql-community-icu-data-files-8.0.33-1.el7.x86_64.rpm

root@mysql \~# rpm -ivh mysql-community-server-8.0.33-1.el7.x86_64.rpm

4、初始化mysqld服务

root@mysql \~# mysqld --initialize --console

5、添加权限 启动服务

root@mysql \~# chown -R mysql:mysql /var/lib/mysql/
root@mysql \~# systemctl start mysqld

6、在/var/log/mysqld.log中找到初始密码,复制

root@mysql \~# cat /var/log/mysqld.log | grep localhost
2024-08-02T01:49:19.435048Z 6 Note MY-010454 Server A temporary password is generated for root@localhost: dQ1o<YO&YNyX 密码

7、登录管理

root@mysql \~# mysql -uroot -p
Enter password: 密码

mysql>

8、设置新的密码

mysql> alter user 'root'@'localhost'identified by '123456';
Query OK, 0 rows affected (0.01 sec)
root@mysql \~# mysql -uroot -p123456

mysql> quit
Bye

9、数据库对象
  1. 数据库系统 DBMS

  2. 数据库 DB

  3. 表 table

  4. 记录 record

  5. 字段 feild

10、数据库操作
1. 数据库操作
1.1 查看数据库
1.2 创建库
1.3 删除库
2. 表的操作
2.1 选择库
2.2 查看表
2.3 创建表

语法:create table user( id int primarykey,username varchar,password varchar );

mysql> create table `test1`(
`id` int not null auto_increment,
`username` varchar(45) not null,
`password` varchar(45) not null,
primary key(`id`)
);

2.4 删除表

mysql> drop table user0;

Query OK, 0 rows affected (0.01 sec)

2.5 其他
2.5.1 新增列

ALTER TABLE `test`

ADD COLUMN `realname` VARCHAR(45) NULL AFTER `password`;

2.5.2 修改列名

mysql> ALTER TABLE `test`

-> CHANGE COLUMN `realname` `zsxm` VARCHAR(45) NULL DEFAULT NULL ; Query OK, 0 rows affected (0.02 sec)

Records: 0 Duplicates: 0 Warnings: 0

2.5.3 删除列

mysql> ALTER TABLE `test`

-> DROP COLUMN `zsxm`;

Query OK, 0 rows affected (0.01 sec)

Records: 0 Duplicates: 0 Warnings: 0

3. 记录的操作
1. 新增

#insert into 表名 (字段名列表) values (字段值列表)

mysql> insert into test (id,username,password) values (3,'zhangsan','zhangsan');

Query OK, 1 row affected (0.01 sec)

mysql> insert into test(username,password)values('lisi','lisi');

Query OK, 1 row affected (0.00 sec)

2. 删除

delte from user where 条件;

mysql> delete from test where username='zhangsan';

Query OK, 1 row affected (0.00 sec)

3. 修改

mysql> insert into user values (1,'zhangsan','zhangsan');

Query OK, 1 row affected (0.00 sec)

mysql> update user set password=123 where username='zhangsan';

Query OK, 1 row affected (0.01 sec)

Rows matched: 1 Changed: 1 Warnings: 0

相关推荐
星释12 小时前
鸿蒙智能体开发实战:23.常见问题
服务器·华为·ai·harmonyos·鸿蒙·智能体
天空'之城12 小时前
Linux 系统编程 22:五种 IO 模型全解
linux
tiancaijiben12 小时前
阿里云SSL证书自动续签与部署完全指南:从托管服务到开源工具全方案解析
数据库
全堆鸿蒙12 小时前
25 数据库设计与表结构规划:5 张表的设计思路
数据库·华为·cocoa·harmonyos
笃行35012 小时前
【金仓数据库产品体验官】_坏得起_实测:备份恢复、PITR 时间穿越与主备切换——KingbaseES V9R3C18 深度体验(三)
数据库
小张成长计划..13 小时前
【Linux】10:冯·诺依曼体系结构和操作系统
linux·运维·服务器
赛博三把手14 小时前
Claude Fable 5 API 调用完整指南:官方、AWS、OpenRouter 与中转平台对比(2026 最新)
网络·云计算·aws
笃行35014 小时前
从兼容到进阶:驱动直连、窗口函数与动态 SQL 实测——KingbaseES V9R3C18 深度体验(二)
数据库
笃行35015 小时前
MySQL 的 JSON 字段迁到金仓还能用吗?——KingbaseES V9R3C18 JSON 操作符与函数兼容实测
数据库
IpdataCloud16 小时前
跨境AI金融风险怎么防?IP风险画像的实战应用指南
数据库·tcp/ip·金融·ip