mysql 的連接
mysql -u 用戶名 -p直接加密碼 或者mysql -u 用戶名 -p
密碼換行輸入
-h 數據庫IP地址,默認127, localhost
-P 端口號
phpmyadmin 部分文件說明
- mysqladmin.exe 可以用來重置密碼日常管理命令
- mysqld mysql重啓關閉開啓
- mysql 用來操作數據庫
- msyqlimport -u root -pPassword [–local] dbname filename.txt [OPTION] 導入數據庫
查看所有數據庫show databases;
使用數據庫use 數據庫名;
查看當前數據庫表名show tables;
在選擇數據庫之後查看錶名
添加數據:
insert into 表名 values("值","值2");// 前提是表裏面有兩個字段,字段1對應 值,字段2對應 值2
或者 insert into 表名 (字段)values("值");
insert into admin (username,password) values("admin","123");
insert into admin (username) values("user"); // 添加的數據要一一對應
查詢數據:
select * from 表名;
select * from admin where username = "admin";
select * from admin where username = admin; // 注意和上面的區別
select * from admin where username != "admin" and password = "111";
select * from admin where username != "admin" or password != "111";
select * from admin where username = "admin" and 1=2;// 條件爲假不執行
select * from admin where 1=2 or 1=1;// 語句執行
修改數據:
update admin set username = '123456';
update admin set username = "123456" where username = "admin";
清空數據:
delete from 表名; // 清空指定的數據表
delete from admin where username = '1123456';// 清空指定的字段名
delete from admin where username != "a";
刪除表:
drop table admin;
desc admin;
備份數據:
show global varlables like "%datadir%"; // 查看數據庫路徑
select * from admin INFO OUTFILE "tmp/1.php";
mysql創建數據庫,創建表,字段
1. 創鍵數據庫
create database 數據庫名字;
2. 使用數據庫
use 數據庫名字;
3. 創建表,字段
create table admin( // 表名
username varchar(20) not null,// 字段名不爲null 空
password text not null); // 字段名
簡書blog:
https://www.jianshu.com/p/5402d381acce
個人自建blog:
http://pigdaqiang.top
http://texttxet.github.io