1. 创建数据库:
CREATE DATABASE mydatabase;
2. 连接到数据库:
USE mydatabase;
3. 创建表格:
CREATE TABLE customers ( id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY, firstname VARCHAR(30) NOT NULL, lastname VARCHAR(30) NOT NULL, email VARCHAR(50), reg_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP );
4. 插入数据:
INSERT INTO customers (firstname, lastname, email) VALUES ('John', 'Doe', 'john@example.com');
5. 查询数据:
SELECT * FROM customers;
6. 更新数据:
UPDATE customers SET lastname='Smith' WHERE id=1;
7. 删除数据:
DELETE FROM customers WHERE id=1;
通过以上步骤,您可以成功创建、连接、操作MySQL数据库。