MySql创建数据库创建表
MySql创建数据库创建表
操作方法
- 01
MySql创建数据库指定字符集 创建数据库指定字符集: UTF8 CREATE DATABASE xiaoyao_db DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci GBK CREATE DATABASE xiaoyao_db DEFAULT CHARACTER SET gbk COLLATE gbk_general_ci
- 02
MySql创建表并设定为主键自动增值 CREATE TABLE person ( personID int NOT NULL AUTO_INCREMENT, PRIMARY KEY(personID), FirstName varchar(15), LastName varchar(15), Age int ) //创建admin表 CREATE TABLE `admin` ( `id` INT(11) NOT NULL AUTO_INCREMENT, `username` CHAR(20) NOT NULL, `password` CHAR(32) NOT NULL, `email` CHAR(32) NOT NULL, PRIMARY KEY(`id`) )ENGINE=INNODB AUTO_INCREMENT=1;
- 03
MySql在PHP语句中insert into INSERT INTO table_name (column1,column2,column3,...) VALUES (values1,values2,values3....);
- 04
Mysql在PHP语句中update语法 UPDATE table_name SET column_name = new_value WHERE column_name = some_value
- 05
Mysql在PHP语句中Delete from语法 DELETE FROM table_name WHERE column_name = some_values;
- 06
注意两点: 1、MySql在PHP语句中insert into常错点 mysql_query(“insert into admin(username,password,age) values(‘vaule’,’vaule’,’vaule’)”); 上面语句执行之前,应该先执行mysql_query(“set names utf8”);以防止数据插入数据之后出现乱码! 2、MySql在PHP语句中update常错点 update数据之前进行mysql_query(“set names utf8”)语句执行,这样才会成功更新数据