本质:对文件内容提供基本的内容操作
mysql -h 127.0.0.1 -P 3306 -u root -p systemctl stop mysqld //停止服务 systemctl start mysqld //开始服务 systemctl restart mysqld //重启服务 创建一个名为helloworld的数据库,相当于建立一个目录
注意:数据库名字加反引号``,是为了防止使用的数据库名刚好是关键字
create database helloworld; 创建一个名为helloworld的数据库,设置字符编码为gbk,直接在后面加上chatset=utf8
create database helloworld chatset=utf8; 创建一个名为helloworld的数据库,设置校验编码,直接加上collate=utf8_general_ci也可以写collate utf8_general_ci
create database helloworld collate=utf8_general_ci; 进入数据库helloworld,相当于cd
use helloworld; show helloworld;//查看helloworld目录 show databasesc;//查看所有数据库 需要先进入对应的数据库,本质是创建文件
create table student( id int, name varchar(32) ); insert into student (id, name) values (1, '张三'); insert into student values (1, '张三');//当后面插入的数据填写完整时,中间的变量名可以省略 查找表student中的信息
select * from student; 删除helloworld的数据库
drop database helloworld; 改变数据库helloworld的编码为utf8
alter database helloworld chatset=utf8; 在root模式下(不是在mysql中),备份helloworld数据库为mytest.sql,输入下面命令后输入密码
mysqldump -P 端口号 -u 用户名 -p -B 数据库名1 数据库名2 ... > 数据库备份存储的文件路径 mysqldump -P3306 -u root -p -B helloworld > mytest.sql 在mysql模式下
source 数据库备份存储的文件路径//具体路径用pwd查 source mytest.sql; 存数据要按照对应编码格式存放,取数据要对应校验规则
show variables like 'character_set_database'; show variables like 'collation_database'; show charset; show collation;