mysql的使用

1官网下载安装包

2解压及安装依赖

tar -xvf mysql-8.0.33-1.el7.x86_64.rpm-bundle.tar 
rpm -ivh mysql-community-common-8.0.33-1.el7.x86_64.rpm 
rmp -ivh mysql-community-client-plugins-8.0.33-1.el7.x86_64.rpm 
rpm -ivh mysql-community-client-plugins-8.0.33-1.el7.x86_64.rpm 
rpm -ivh mysql-community-libs-8.0.33-1.el7.x86_64.rpm 
rpm -ivh mysql-community-client-8.0.33-1.el7.x86_64.rpm 
rpm -ivh mysql-community-icu-data-files-8.0.33-1.el7.x86_64.rpm 
rpm -ivh mysql-community-server-8.0.33-1.el7.x86_64.rpm 

3初始化,开启服务

systemctl start mysqld

4查看初始密码,登录mysql

cd /var/log
grep -n password mysqld.log


 mysql -u root -p 

操作

1删除库
mysql> drop database test;
Query OK, 0 rows affected (0.01 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)

2创建库

mysql> create datababse test charset utf8;
Query OK, 1 row affected, 1 warning (0.01 sec)
mysql> show databases;
|

3查看库

show databases;
 

4选择库

use mysql;
 

5查看表

show tables;

6创建表

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';

7删除表

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)

8新增列

ALTER TABLE `test`.`user`
ADD COLUMN `realname` VARCHAR(45) NULL AFTER `password`;

9删除列

mysql> ALTER TABLE `test`.`user`  DROP COLUMN `zsxm`;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值