2021-09-27

创建一个myschool的数据库,并指定其字符编码集为gbk

mysql> create database myschool character set gbk;

查询该数据库的定义信息

mysql> show create database myschool;
+----------+------------------------------------------------------------------------------------------------------+
| Database | Create Database                                                                                      |
+----------+------------------------------------------------------------------------------------------------------+
| myschool | CREATE DATABASE `myschool` /*!40100 DEFAULT CHARACTER SET utf8 */ /*!80016 DEFAULT ENCRYPTION='N' */ |
+----------+------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

更换数据库的编码集为utf8

mysql> alter database myschool default character set utf8;

使用myschool数据库,并查看使用状态

mysql> use myschool;
Database changed
mysql> select database();
+------------+
| database() |
+------------+
| myschool   |
+------------+
1 row in set (0.00 sec)

删除myschool数据库

mysql> drop database myschool;

用判断方式创建myschool数据库

mysql> create database if not exists myschool;

以下为完整代码

C:\WINDOWS\system32>mysql -uroot #root是系统账号 -p #这里需要回车一下
Enter password: *********
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 13
Server version: 8.0.26 MySQL Community Server - GPL

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> create database myschool character set gbk;
Query OK, 1 row affected (0.00 sec)
mysql> alter database myschool default character set utf8;
Query OK, 1 row affected, 1 warning (0.00 sec)
mysql> use myschool;
Database changed
mysql> select database();
+------------+
| database() |
+------------+
| myschool   |
+------------+
1 row in set (0.00 sec)

mysql> drop database myschool;
Query OK, 0 rows affected (0.00 sec)

mysql> create database if not exists myschool;
Query OK, 1 row affected, 1 warning (0.00 sec)
上一篇:HttpServletRequest对象getParameter()方法在各web容器中返回值问题和null不可以toString


下一篇:老男孩-学习笔记day42