创建数据库
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密码
版权声明:本文为Daniel_WL原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。