数据库--->本地/远程存储--->文件夹
mysql> show databases;查询当前所有的数据库名称
+--------------------+
| Database |
+--------------------+
| information_schema |内置配置数据库
| mysql |mysql存储很多相关表:user表
| performance_schema |mysql性能优化数据库
| test |测试数据库(里面没有表-->创建表-->将表存储在test数据库进行测试)
+--------------------+
4 rows in set (0.00 sec)创建数据库:
create database 数据名;
mysql> create database db2;
Query OK, 1 row affected (0.00 sec)create database if not exists 数据库名称; 如果不存在 该数据库名称 创建一个新的数据库!
mysql> create database if not exists db4;
Query OK, 1 row affected (0.00 sec)
mysql> show create database db2;//查看当前创建数据库db2的默认字符集
+----------+----------------------------------------------------------------+
| Database | Create Database |
+----------+----------------------------------------------------------------+
| db2 | CREATE DATABASE `db2` /*!40100 DEFAULT CHARACTER SET latin1 */ |
+----------+----------------------------------------------------------------+
1 row in set (0.00 sec)
创建数据库的同时,修改当前数据库的默认字符集
create database if not exists 数据名 default(可省略) character set gbk(指定默认字符集);
mysql> create database if not exists db6 default character set gbk;
Query OK, 1 row affected (0.00 sec)
mysql> show create database db6;
+----------+-------------------------------------------------------------+
| Database | Create Database |
+----------+-------------------------------------------------------------+
| db6 | CREATE DATABASE `db6` /*!40100 DEFAULT CHARACTER SET gbk */ |
+----------+-------------------------------------------------------------+
1 row in set (0.00 sec)
修改数据库默认字符集
mysql> alter database db2 default(可以省略) character set gbk;
Query OK, 1 row affected (0.00 sec)mysql> show create database db2;
+----------+-------------------------------------------------------------+
| Database | Create Database |
+----------+-------------------------------------------------------------+
| db2 | CREATE DATABASE `db2` /*!40100 DEFAULT CHARACTER SET gbk */ |
+----------+-------------------------------------------------------------+
1 row in set (0.00 sec)删除数据库:
drop database 数据名;
mysql> drop database db2;
Query OK, 0 rows affected (0.00 sec)
mysql> show create database db2;
ERROR 1049 (42000): Unknown database 'db2'判断删除:如果存在数据库,删除数据库
mysql> drop database if exists db3;
Query OK, 0 rows affected (0.00 sec)
默认查询"内置变量"所有的相关字符集 (在dos中使用,创建表,给表中添加数据,会出现中文乱码)
//修改character_set_client的字符集
//character_set_results 的字符集
mysql> show variables like '%character%';