安装mysqul应该是没有问题的;就简单说一下在window系统下怎样配置环境变量:
第一步:找到安装目录:如d\phpstudy\mysql\bin
第二步:计算机-右键点击属性-高级系统设置-环境变量或直接搜索高级设置
系统变量中新建变量中新建变量
名称:mysql_home地址:d\phpstudy\mysql\bin.
path中加入:%mysql_home%;点击确认。
操作数据库:
cmd 打开 输入 mysql -h 127.0.0.1 -u root -proot
查看默认数据库 show databases;
操作某个数据库:use 数据库名称;
查看数据库下的表格:show tables;
查询某个表格中的所有数据;
select * from 表格名
创建数据库:
create database school default charset utf8 ;
创建表格:
create table students (
id char(10),
name char(30),
score char(10),
) default charset utf8;
添加数据
insert into students (id ,name, score)
values("01","zhongshan","90");
记录日志
mysql:tee-d/-/-/(文件名称);
数据库增,删,改,查。
查询
select * from student;
条件查询
select * from score where degree >80 ;
关联查询
select student student(表).name(表里面的列),score(表).degree(表里里面的列) from student,score
where score.degree>80 and student.name=score.name;
修改
update student set brithday="1999-3-3"where son="101;
删除数据库
drop student(表格) from school(数据库)
drop school(school是数据库)
PHP中连接数据库及操作数据库
1.连接数据库
信息
$host="127.0.0.1";
$user="root";
$password="root";
$database="stu";
$link = mysqli_connect($host,$user,$passeord,$database);
if($link===false){
exit("错误")
2.设置字符编码格式
mysqli_set_charset($link,"utf8");
3.执行请求
$sql="select *from student where sname ="'.$name.'" and pwd="'.$p';"
$ result = myqli_query($link,$spl);
if($result ===false){
echo "错误编码".myquli_errno($link);
echo "错误信息"myquli_error($link);
4解析结果只解析一行
$arr =mysqli_fetch_row($result);
if($arr!=null){
说明有该条信息
}
php操作数据库语句
增,删,该,查
1.增加写入
$query="insert into student (no, name, sex)
value("$no","$name","$sex");";
$result =myqli_query($link,$query);
2.删除
$query="delete from student where no="$no";"
$result =myqli_query($link,$query);
3.修改
$query = "update student set name="$name",brithday='".$birthday.'" where no="122";
$result =myqli_query($link,$query);
4.查询
$sql="select * from student where name='$suename' and pwd='$pwd';"
$result =myqli_query($link,$query);