欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

有关mysql数据库的操作

程序员文章站 2024-03-21 21:17:28
...

数据库连接:mysql -uroot -p

设置密码:mysqladmin -uroot -p password 密码

查看当前环境下所有的数据库:show databases;

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sakila             |
| studentcourse      |
| test               |
| world              |
+--------------------+
7 rows in set (0.34 sec)

数据库解释:

information_schema 数据库的一些基础数据
mysql 数据库的配置信息,包括用户信息
performance_schema 数据库软件的运行数据,日志信息,性能数据
test 测试数据库

数据库的创建:create database 数据库名

 指定默认字符集:default character set utf8; 

mysql> create database student
    -> default character set utf8;
Query OK, 1 row affected (0.05 sec)

mysql>
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sakila             |
| student            |
| studentcourse      |
| test               |
| world              |
+--------------------+
8 rows in set (0.00 sec)

 

查看数据库的默认字符集:show create database student;

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

删除数据库:


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

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sakila             |
| studentcourse      |
| test               |
| world              |
+--------------------+
7 rows in set (0.00 sec)

修改数据库字符集:

mysql> alter database student default character set utf8;
Query OK, 1 row affected (0.02 sec)