- 官网下载或者 wget
[root@mysql ~] # ls
anaconda-ks.cfg
initserver.sh
mysql-8.0.33-1.el7.x86_64.rpm-bundle.tar
mysql-community-client-8.0.33-1.el7.x86_64.rpm
mysql-community-client-plugins-8.0.33-1.el7.x86_64.rpm
mysql-community-common-8.0.33-1.el7.x86_64.rpm
mysql-community-debuginfo-8.0.33-1.el7.x86_64.rpm
mysql-community-devel-8.0.33-1.el7.x86_64.rpm
mysql-community-embedded-compat-8.0.33-1.el7.x86_64.rpm
mysql-community-icu-data-files-8.0.33-1.el7.x86_64.rpm
mysql-community-libs-8.0.33-1.el7.x86_64.rpm
mysql-community-libs-compat-8.0.33-1.el7.x86_64.rpm
mysql-community-server-8.0.33-1.el7.x86_64.rpm
mysql-community-server-debug-8.0.33-1.el7.x86_64.rpm
mysql-community-test-8.0.33-1.el7.x86_64.rpm - 确定 mysql-community-server 正常安装之后就可以开始配置
- 初始化 mysqld 服务 mysqld initeialize
- 启动服务 systemctl start mysqld
- 添加开机启动列表 systecmctrl enable mysqld
- 在 /var/log/mysql.log 中找到初始密码,前后复制空格 7. 登录管理 mysql -uroot -p
将复制的密码粘贴到输入密码的区
域,实现登录 - 设置新的密码
- 退出登录
1. 数据库的对象 - 数据库系统 DBMS
- 数据库
DB - 表
table - 记录
record - 字段
feild
1. 数据库操作
删除库
创建库
mysql > create datababse test charset utf8;
Query OK, 1 row affected, 1 warning ( 0.01 sec )
mysql > show databases ; 查看库
2. 表的操作
1. 选择库
+--------------------+
mysql > create datababse test charset utf8;
Query OK, 1 row affected, 1 warning ( 0.01 sec )
mysql > show databases ; 查看库
2. 表的操作
1. 选择库
2. 查看表
3. 创建表
mysql > CREATE TABLE `test` . `user` (
-> `id` INT NOT NULL AUTO_INCREMENT ,
-> `username` VARCHAR ( 45 ) NOT NULL ,
-> `password` VARCHAR ( 45 ) NOT NULL ,
-> PRIMARY KEY ( `id` ) ,
-> UNIQUE INDEX `username_UNIQUE` ( `username` ASC )
VISIBLE )
-> COMMENT = 'us' ;
mysql > show tables ;
+----------------+
| Tables_in_test |
+----------------+
| user |
| user0 |
4. 删除表
新增列
mysql > show tables ;
+----------------+
| Tables_in_test |
+----------------+
| user |
| user0 |
+----------------+
2 rows in set ( 0.00 sec )
mysql > drop table user0;
Query OK, 0 rows affected ( 0.01 sec )
mysql > show tables ;
+----------------+
| Tables_in_test |
+----------------+
| user |
+----------------+
1 row in set ( 0.01 sec )
ALTER TABLE `test`.`user`
ADD COLUMN `realname` VARCHAR(45) NULL AFTER `password`;
mysql> desc 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 |
|
| realname | varchar(45) | YES | | NULL |
|
+----------+-------------+------+-----+---------+---------
-------+
4 rows in set (0.01 sec)
mysql> ALTER TABLE `test`.`user`
-> CHANGE COLUMN `realname` `zsxm` VARCHAR(45) NULL
DEFAULT NULL ;
Query OK, 0 rows affected (0.02 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> desc 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 |
|
| zsxm | varchar(45) | YES | | NULL |
|
+----------+-------------+------+-----+---------+---------
-------+ 删除列 - 其他
- 记录的操作
- 新增
mysql > ALTER TABLE `test` . `user`
-> DROP COLUMN `zsxm` ;
Query OK, 0 rows affected ( 0.01 sec )
Records: 0 Duplicates: 0 Warnings : 0
mysql > desc 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.00 sec )
#insert into 表名 ( 字段名列表 ) values ( 字段值列表 )
mysql > select * from user ;
Empty set ( 0.00 sec )
mysql > insert into user ( id,username, password ) values
( 3 , 'zhangsan' , 'zhangsan' ) ; Query OK, 1 row affected ( 0.01 sec )
mysql > select * from user ;
+----+----------+----------+
| id | username | password |
+----+----------+----------+
| 3 | zhangsan | zhangsan |
+----+----------+----------+
1 row in set ( 0.00 sec )
mysql > select * from user ;
+----+----------+----------+
| id | username | password |
+----+----------+----------+
| 3 | zhangsan | zhangsan |
+----+----------+----------+
1 row in set ( 0.00 sec )
mysql > insert into
user ( username, password ) values ( 'lisi' , 'lisi' ) ;
Query OK, 1 row affected ( 0.00 sec )
mysql > select * from user ;
+----+----------+----------+
| id | username | password |
+----+----------+----------+
| 3 | zhangsan | zhangsan |
| 4 | lisi | lisi |
+----+----------+----------+
2 rows in set ( 0.00 sec )
mysql > desc 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.00 sec ) - 删除
delte from user where 条件 ;
mysql > delete from user where username = 'zhangsan' ;
Query OK, 1 row affected ( 0.00 sec )
mysql > select * from user ;
+----+----------+----------+
| id | username | password |
+----+----------+----------+
| 4 | lisi | lisi |
+----+----------+----------+
1 row in set ( 0.00 sec )
mysql > delete from user ;
Query OK, 1 row affected ( 0.00 sec ) mysql > select * from user ;
Empty set ( 0.00 sec ) - 修改
mysql >
mysql > insert into user values
( 1 , 'zhangsan' , 'zhangsan' ) ;
Query OK, 1 row affected ( 0.00 sec )
mysql > insert into user values ( 2 , 'lisi' , 'lisi' ) ;
Query OK, 1 row affected ( 0.00 sec )
mysql > insert into user values ( 3 , 'wangwu' , 'wangwu' ) ;
Query OK, 1 row affected ( 0.00 sec )
mysql > select * from user ;
+----+----------+----------+
| id | username | password |
+----+----------+----------+
| 1 | zhangsan | zhangsan |
| 2 | lisi | lisi |
| 3 | wangwu | wangwu |
+----+----------+----------+
3 rows in set ( 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
mysql > select * from user ;
+----+----------+----------+
| id | username | password |
+----+----------+----------+
| 1 | zhangsan | 123 | | 2 | lisi | lisi |
| 3 | wangwu | wangwu |
+----+----------+----------+
3 rows in set ( 0.00 sec ) - 查询
数据库的安装初始化及管理
祈愿平安&2024-08-03 11:03
相关推荐
陈燚_重生之又为程序员11 分钟前
基于梧桐数据库的实时数据分析解决方案caridle13 分钟前
教程:使用 InterBase Express 访问数据库(五):TIBTransaction白云如幻15 分钟前
MySQL排序查询萧鼎16 分钟前
Python并发编程库:Asyncio的异步编程实战^velpro^18 分钟前
数据库连接池的创建荒川之神23 分钟前
ORACLE _11G_R2_ASM 常用命令IT培训中心-竺老师29 分钟前
Oracle 23AI创建示例库小白学大数据1 小时前
JavaScript重定向对网络爬虫的影响及处理time never ceases1 小时前
使用docker方式进行Oracle数据库的物理迁移(helowin/oracle_11g)Frank牛蛙1 小时前
1.每日SQL----2024/11/7