1. 程式人生 > >DBA:多方式建庫表數據庫表

DBA:多方式建庫表數據庫表

copy oot 字段名 搜索 創建數據庫失敗 ren mariadb nds man

提醒:
創建 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:多方式建庫表數據庫表