数据库的安装初始化及管理

  1. 官网下载或者 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
  2. 确定 mysql-community-server 正常安装之后就可以开始配置
  3. 初始化 mysqld 服务 mysqld initeialize
  4. 启动服务 systemctl start mysqld
  5. 添加开机启动列表 systecmctrl enable mysqld
  6. 在 /var/log/mysql.log 中找到初始密码,前后复制空格 7. 登录管理 mysql -uroot -p
    将复制的密码粘贴到输入密码的区
    域,实现登录
  7. 设置新的密码
  8. 退出登录

    1. 数据库的对象
  9. 数据库系统 DBMS
  10. 数据库
    DB

  11. table
  12. 记录
    record
  13. 字段
    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 |
    |
    +----------+-------------+------+-----+---------+---------
    -------+ 删除列
  14. 其他
  15. 记录的操作
  16. 新增
    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 )
  17. 删除
    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 )
  18. 修改
    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 )
  19. 查询
相关推荐
陈燚_重生之又为程序员11 分钟前
基于梧桐数据库的实时数据分析解决方案
数据库·数据挖掘·数据分析
caridle13 分钟前
教程:使用 InterBase Express 访问数据库(五):TIBTransaction
java·数据库·express
白云如幻15 分钟前
MySQL排序查询
数据库·mysql
萧鼎16 分钟前
Python并发编程库:Asyncio的异步编程实战
开发语言·数据库·python·异步
^velpro^18 分钟前
数据库连接池的创建
java·开发语言·数据库
荒川之神23 分钟前
ORACLE _11G_R2_ASM 常用命令
数据库·oracle
IT培训中心-竺老师29 分钟前
Oracle 23AI创建示例库
数据库·oracle
小白学大数据1 小时前
JavaScript重定向对网络爬虫的影响及处理
开发语言·javascript·数据库·爬虫
time never ceases1 小时前
使用docker方式进行Oracle数据库的物理迁移(helowin/oracle_11g)
数据库·docker·oracle
Frank牛蛙1 小时前
1.每日SQL----2024/11/7
数据库·sql