1、启动并登陆MySQL
C:\WINDOWS\system32>mysql -uroot -p Enter password: ****** Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 5 Server version: 5.5.44 MySQL Community Server (GPL)
2、修改操作符,查看版本
mysql> prompt \u@\h \d> PROMPT set to '\u@\h \d>' root@localhost (none)>use test; Database changed root@localhost test>select version(); +-----------+ | version() | +-----------+ | 5.5.44 | +-----------+ 1 row in set (0.00 sec)
3、查看当前的时间和用户
root@localhost test>select now(); +---------------------+ | now() | +---------------------+ | 2017-07-16 10:27:53 | +---------------------+ 1 row in set (0.00 sec)
root@localhost test>select user(); +--------+ | user() | +--------+ | root@ | +--------+ 1 row in set (0.00 sec) 4、创建数据库,查看所有数据库
root@localhost test>CREATE DATABASE t1; Query OK, 1 row affected (0.00 sec)
root@localhost test>SHOW DATABASES; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | t1 | | test | +--------------------+ 5 rows in set (0.00 sec)
5、重复创建数据库及警告查看
root@localhost test>CREATE DATABASE t1; ERROR 1007 (HY000): Can't create database 't1'; database exists root@localhost test>CREATE DATABASE IF NOT EXISTS t1; Query OK, 1 row affected, 1 warning (0.00 sec) root@localhost test>SHOW WARNINGS; +-------+------+---------------------------------------------+ | Level | Code | Message | +-------+------+---------------------------------------------+ | Note | 1007 | Can't create database 't1'; database exists | +-------+------+---------------------------------------------+ 1 row in set (0.00 sec)
6、查看数据库编码方式与修改编码方式
root@localhost test>SHOW CREATE DATABASE t2; +----------+------------------------------------------------------------+ | Database | Create Database | +----------+------------------------------------------------------------+ | t2 | CREATE DATABASE `t2` /*!40100 DEFAULT CHARACTER SET gbk */ | +----------+------------------------------------------------------------+ 1 row in set (0.00 sec)
root@localhost test>ALTER DATABASE t2 CHARACTER SET = utf8; Query OK, 1 row affected (0.00 sec)
7、查看数据库和删除数据库
root@localhost test>DROP DATABASE t1; Query OK, 0 rows affected (0.01 sec) root@localhost test>SHOW DATABASES; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | t2 | | test | +--------------------+ 5 rows in set (0.00 sec)