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

  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. 查询
相关推荐
sdaxue.com1 小时前
帝国CMS:如何去掉帝国CMS登录界面的认证码登录
数据库·github·网站·帝国cms·认证码
o(╥﹏╥)2 小时前
linux(ubuntu )卡死怎么强制重启
linux·数据库·ubuntu·系统安全
阿里嘎多学长2 小时前
docker怎么部署高斯数据库
运维·数据库·docker·容器
Yuan_o_2 小时前
Linux 基本使用和程序部署
java·linux·运维·服务器·数据库·后端
Sunyanhui12 小时前
牛客网 SQL36查找后排序
数据库·sql·mysql
老王笔记2 小时前
MHA binlog server
数据库·mysql
lovelin+v175030409663 小时前
安全性升级:API接口在零信任架构下的安全防护策略
大数据·数据库·人工智能·爬虫·数据分析
DT辰白4 小时前
基于Redis的网关鉴权方案与性能优化
数据库·redis·缓存
2401_871213304 小时前
mysql高阶语句
数据库·mysql