基本语法增删改查
mysql> show databases; //查看数据库
+--------------------+
| Database |
+-----------------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+-----------------------------+
mysql> use mysql; //查看当前使用库中的所有表
mysql> create database school; //添加新的数据库
mysql> show databases;
+----------------------------+
| Database |
+----------------------------+
| information_schema |
| mysql |
| performance_schema |
| school |
| sys |
+-----------------------------+
mysql> drop database school; //删除一个数据库
Query OK, 3 rows affected (0.03 sec)
mysql> show databases;
+-----------------------------+
| Database |
+-----------------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+-----------------------------+
mysql> use ccc; //切换到ccc数据库中 可以删除添加表
mysql> show tables; //查看所在库中的表
Empty set (0.00 sec) //有表则会显示表 没有则显示提示语句
mysql> create table info (id int,name char(10),scre decimal(5.2));
//创建列 自定义即可 (id int) id
类型为整型 (name char(10)) 名字 类型为可边长字符串
(scre decimal(5.2)) 成绩 类型为双精度类型
5位数并且保留小数点后两位 如 考试成绩分数
mysql> show tables; //再次查看就有出现
+--------------------+
| Tables_in_ccc |
+-------------------+
| info |
| soso | //准备删除它如下
+-------------------+
mysql> drop table soso; //删除的前提得是在当所在库中对列表进修改删除
mysql> show tables;
+-------------------+
| Tables_in_ccc |
+-------------------+
| info |
+-------------------+
mysql> insert into info (id,name) values (1,'zhangsan');
添加列的信息要一一对于应
mysql> select * from info; //查看所有表
+------+----------+-----------+
| id | name | scre |
+------+----------+-----------+
| 1 | zhangsan | NULL |
+------+----------+----------+
| 2 | lisi | NULL |
+------------------------------+
mysql> delete from info where id=2; //删除表中 id=2的信息
mysql> select * from info; //查看所有表
+------+----------+------+
| id | name | scre |
+------+----------+------+
| 1 | zhangsan | NULL |
+------------------------+
MySQL 用户管理
[root@localhost ~]# mysql -u root -p //登陆数据库
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| ccc |
| mysql | //系统数据库
| performance_schema |
| sys |
+--------------------+
mysql> use mysql; //进入表才可以增加修改删除
select user,authentication_string,host from user; //查询user表中的用户、密码、主机三列数据
用户添加,删除
-明文转密文
mysql> select password('112233'); //会自动生成对于密文反知·
mysql> create user 'ccc'@'localhost' identified by '112233'; | //在'112233'处换成秘闻的方式在
登陆输入的时候其实是'112233'
+-------------------------------------------+
| password('112233') |
+-------------------------------------------+
| *C42CF059802456312318BB928C3334F1A6133AB4 |
+-------------------------------------------+
set password=password('123123'); //修改当前登陆用户密码
set password for 'cx'@'localhost'=password('123456'); //修改其他用户密码
mysql> drop user 'xxx'@'localhost'; //删除用户
遗忘root密码
[root@localhost ~]# netstat -ntao | grep 3306 //检查端口要起先关闭
tcp6 0 0 :::3306 :::* LISTEN off (0.00/0/0)
[root@localhost ~]# systemctl stop mysqld.service //关闭服务 若卡则重启系统
[root@localhost ~]# netstat -ntao | grep 3306
[root@localhost ~]# mysqld --skip-grant-tables //重新开一个终端进入
mysql> update mysql.user set authentication_string=password('123456') where user='root'; //修改root密码为123456
mysql> flush privileges;
//刷新一下就OK了