MYSQL数据库操作基本命令:
Login database:
mysql -h 127.0.0.1 -u username -p admin
Watch database/tables:
show databases;
show tables;
watch tables-type:
desc table-name;
query table structure:
Select * from table-name;
Import sql-decument
source sql文件的路径;
create-tabels-e.g
create table ming( id int not null auto_increment , name int default null,primary key(id) );
CREATE TABLE employee (id int(10),name char(20),phone int(12));
Insert-date:
insert into table-name
values (1
,1
);
INSERT INTO employee(id,name,phone) VALUES(01,‘Tom’,110110110);
数据类型是 CHAR 、VARCHAR,TEXT,DATE,TIME,ENUM 等类型的数据也需要单引号修饰,而
INT,FLOAT,DOUBLE 等则不需要
Alter-date
alter table table-name
add( or drop) 字段名 类型 修饰 after 某列【把新列加在某列后面】
alter table ming
add age int (20) after name;
update user set name=新值 where id=1
delete-date
Drop databases-name/tables-name;
Delete from table-name where id =1
;
Date-type
整数: tinyint、smallint、mediumint、int、bigint 浮点数:
float、double、real、decimal 日期和时间: date、time、datetime、timestamp、year
字符串: char、varchar 文本: tinytext、text、mediumtext、longtext
二进制(可用来存储图片、音乐等): tinyblob、blob、mediumblob、longblob
mysql脚本
错误更改
1 sql语句不区分大小写。
2 引入``反引号区分关键字和普通字符。error 1064
3 数据库名称错误或没有创建。error1146
数据输出
<?php
// 创建连接
if($con = mysqli_connect("127.0.0.1","apple","111111", "test")){
echo 'connected';
}else{
echo 'fail';
}
// 检测连接
$sql = 'select * from article';
$query =mysqli_query($con,$sql);
while ($first=mysqli_fetch_assoc($query)) {
$list[] =$first;
}
foreach($list as $key=>$row){
echo "<hr/>";
echo "<tr>";
echo "<p> 编号:<td>{$row['id']}  </td></p> ";
echo "<p>文章标题:<td>{$row['title']}</td></p> ";
echo "<p>文章作者:<td>{$row['author']}</td></p> ";
echo "<p>上传时间:<td>{$row['addtime']}</td></p> ";
echo "<p>文章内容:<td>{$row['content']}</td></p> ";
echo "<p><td>提交 下载 删除 批示</td></p> </br>";
echo "<tr>";
echo "<hr/>";
}
?>
数据输入
``new3.php`
<?php $title=$_POST['title']; $author=$_POST['author']; echo $title; $link = @mysql_connect('127.0.0.1','root','admin','test'); if (!$link){ die('Could not connect to MySQL: ' . mysql_error()); }else{ echo "MySQL connection-->"; $result =@mysql_select_db("test"); if($result){ echo "database has been linked-->"; }else{ echo "Not link"; } if($title == "" || $author == "" ) { echo ""; } } } mysqli_close($con); ?>**article.sql**
/*
Navicat MySQL Data Transfer
Source Server : local
Source Server Version : 50067
Source Host : localhost:3306
Source Database : test
Target Server Type : MYSQL
Target Server Version : 50067
File Encoding : 65001
Date: 2020-06-19 11:18:17
*/
SET FOREIGN_KEY_CHECKS=0;
– Table structure for article
DROP TABLE IF EXISTS article
;
CREATE TABLE article
(
aid
int(255) NOT NULL auto_increment,
title
char(255) NOT NULL,
author
char(255) NOT NULL,
PRIMARY KEY (aid
)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
– Records of article
可能有些许错误,各位同行指正。