前言
MySQL命令行基本操作
查看你有哪些库:show databases;
mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | imageps | | mysql | | performance_schema | | sys | | wp.cc | +--------------------+ 6 rows in set (0.00 sec) mysql>
创建数据库:create database 数据库名 charset=utf8; (charset=utf8 最好加上)
mysql> create database back_system charset=utf8; Query OK, 1 row affected (0.00 sec) mysql>
删除数据库:drop database 数据库名
mysql> drop database back_system -> ; Query OK, 0 rows affected (0.00 sec) mysql>
修改数据库的字符编码,之前我们创建的是utf8,可以修改成gbk:alter databases user charset=gbk;
mysql> alter databases back_system charset=gbk; Query OK, 0 rows affected (0.00 sec) mysql>
查询你创建的数据库sql语句:show create database user;
mysql> show create database back_system; +-------------+----------------------------------------------------------------------+ | Database | Create Database | +-------------+----------------------------------------------------------------------+ | back_system | CREATE DATABASE `back_system` /*!40100 DEFAULT CHARACTER SET utf8 */ | +-------------+----------------------------------------------------------------------+ 1 row in set (0.00 sec) mysql>
使用数据库:use 数据库名
mysql> use back_system; Database changed mysql>
查看当前使用的数据库:select database();
mysql> select database(); +-------------+ | database() | +-------------+ | back_system | +-------------+ 1 row in set (0.00 sec) mysql>
查看数据库全部表:show tables;
mysql> show tables; Empty set (0.00 sec) mysql>