码迷,mamicode.com
首页 > 数据库 > 详细

DBA:多方式建库表数据库表

时间:2018-08-29 01:20:09      阅读:241      评论:0      收藏:0      [点我收藏+]

标签:符号   -o   .com   lin   技术   serve   编码   src   root   

提醒:
创建 MySql 的表时,表名和字段名外面的符号 ` 不是单引号,而是英文输入法状态下的反单引号,键盘左上角 esc 按键下面的那一个 ~ 按键。

在每一条语句的终止符都是‘;’

一、命令行建库表

[root@mysql-linuxview ~]# mysql -uroot -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MySQL connection id is 36
Server version: 5.7.18-log Source distribution

Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.

Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.

MySQL [(none)]> create database linuxview;
Query OK, 1 row affected (0.00 sec)

MySQL [(none)]> use linuxview;
Database changed
MySQL [linuxview]> create table lv1(id int(4),name varchar(10),mark varchar(10)) engine=innodb default charset=utf8;
Query OK, 0 rows affected (0.40 sec)

MySQL [linuxview]> show tables;
+---------------------+
| Tables_in_linuxview |
+---------------------+
| lv1 |
+---------------------+
1 row in set (0.00 sec)

MySQL [linuxview]>

说明:
如果不想字段为空,可以在字段属性后添加 not null,在插入数据的时如果该字段为NULL会报错。
engine设置搜索引擎
charset设置编码

二、PHP建库表

语法:
mysqli_query(connection,query,resultmode);
技术分享图片

{
die(‘创建数据库失败:‘ . mysqli_query($conn));
}
echo "创建数据表成功\n";
mysqli_close($conn);
?>
[root@mysql-linuxview web]#

效果:
技术分享图片

技术分享图片

查看数据库:
MySQL [(none)]> use viewtest;
Database changed
MySQL [viewtest]> show tables;
+--------------------+
| Tables_in_viewtest |
+--------------------+
| lv1 |
+--------------------+
1 row in set (0.00 sec)

MySQL [viewtest]>

DBA:多方式建库表数据库表

标签:符号   -o   .com   lin   技术   serve   编码   src   root   

原文地址:http://blog.51cto.com/leoheng/2165718

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!