创建数据库
mysql> create database python3 charset=utf8;
Query OK, 1 row affected
创建表:
mysql> use python3;
Database changed
mysql> create table student(
-> id int auto_increment primary key,
-> sname varchar(10) not null,
-> sage int not null,
-> gender varchar(10) not null,
-> class varchar(10) not null);
Query OK, 0 rows affected
全列插入:
mysql> insert into student values(1,"小明","7","男","一班");
Query OK, 1 row affected
缺省插入:
mysql> insert into student(sname,sage) values("小红",8);
Query OK, 1 row affected
多行插入:
mysql> insert into student values(3,"小一",7,"男","二班"),(4,"小二",7,"男","二班"),(5,"小程",7,"男","二班");
Query OK, 3 rows affected
Records: 3 Duplicates: 0 Warnings: 0
数据备份
进入超级管理员
sudo -s
windows下直接管理员权限运行命令行
进入mysql库目录
cd /var/lib/mysql
运行mysqldump命令
mysqldump –uroot –p 数据库名 > ~/Desktop/备份文件.sql;
按提示输入mysql的密码

数据恢复
连接mysqk,创建数据库
退出连接,执行如下命令
mysql -uroot –p 数据库名 < ~/Desktop/备份文件.sql
根据提示输入mysql密码

本文介绍了如何在MySQL中创建数据库和表,包括全列插入、缺省插入和多行插入的方法。同时,详细讲解了数据备份和恢复的步骤,涉及使用mysqldump进行备份,以及通过mysql命令进行数据恢复。
785

被折叠的 条评论
为什么被折叠?



