1.创建数据库 mysqladmin
下面是一个简单的例子,创建名为 yiibai_tutorials1 的数据库。 D:softwaremysql-5.6.25-winx64in> mysqladmin -u root -p create yiibai Enter password:<回车> 或 D:softwaremysql-5.6.25-winx64in> mysql -u root -p Enter password: mysql>create database yiibai;
使用PHP脚本创建数据库 mysql_query() bool mysql_query( sql, connection );
<html> <head> <title>创建MySQL数据库</title> </head> <body> <?php $dbhost = 'localhost:3036'; $dbuser = 'root'; $dbpass = ''; $conn = mysql_connect($dbhost, $dbuser, $dbpass); if(! $conn ) { die('Could not connect: ' . mysql_error()); } echo 'Connected successfully<br />'; $sql = 'CREATE DATABASE yiibai'; $retval = mysql_query( $sql, $conn ); if(! $retval ) { die('Could not create database: ' . mysql_error()); } echo "Database yiibai created successfully "; mysql_close($conn); ?>
</body>
</html>
2.建表 CREATE TABLE table_name (column_name column_type);
create table emp( id int, ename varchar(30), age int, job varchar(20) );
2.