今天分享的是修改数据库,删除数据库和查看数据库:
修改数据库
#先创建数据库
mysql> create database db1 character set utf8 collate utf8_bin;
Query OK, 1 row affected, 2 warnings (0.00 sec)
#然后修改数据库
mysql> alter database db1 character set utf8 collate utf8_bin;
Query OK, 1 row affected, 2 warnings (0.02 sec)
#查看该数据库
mysql> show create database db1;
+----------+------------------------------------------------------------------------------------------------------------------------+
| Database | Create Database |
+----------+------------------------------------------------------------------------------------------------------------------------+
| db1 | CREATE DATABASE `db1` /*!40100 DEFAULT CHARACTER SET utf8mb3 COLLATE utf8mb3_bin */ /*!80016 DEFAULT ENCRYPTION='N' */ |
+----------+------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
[root@ubuntu2204 ~]#cat /var/lib/mysql/db1/db.opt
default-character-set=utf8
default-collation=utf8_general_ci
删除数据库
#删除不需要的数据库
mysql> drop database db1;
Query OK, 0 rows affected (0.02 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.01 sec)
[root@ubuntu2204 ~]#ls /var/lib/mysql/
auto.cnf client-cert.pem mysql.ibd
binlog.000001 client-key.pem performance_schema
binlog.000002 debian-5.7.flag private_key.pem
binlog.000003 '#ib_16384_0.dblwr' public_key.pem
binlog.000004 '#ib_16384_1.dblwr' server-cert.pem
binlog.000005 ib_buffer_pool server-key.pem
binlog.000006 ibdata1 sys
binlog.000007 ibtmp1 ubuntu2204.wang.pid
binlog.index '#innodb_redo' undo_001
ca-key.pem '#innodb_temp' undo_002
ca.pem mysql
查看数据库列表
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.01 sec)
总结:数据库的创建,删除和查看功能是MySQL数据库的基础,所以总的就是对命令的使用。其使用方法就是针对create (创建), alter (修改),drop (删除)的使用。