MySQL数据库基础操作
2022/6/13 2:20:22
本文主要是介绍MySQL数据库基础操作,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
创建一个字符集为utf8的数据库
mysql> create database lisi DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
Query OK, 1 row affected (0.00 sec)
查看创建的数据库
mysql> show create database lisi;
+----------+---------------------------------------------------------------+
| Database | Create Database |
+----------+---------------------------------------------------------------+
| lisi | CREATE DATABASE `lisi` /*!40100 DEFAULT CHARACTER SET utf8 */ |
+----------+---------------------------------------------------------------+
1 row in set (0.00 sec)
删除数据库lisi
mysql> drop database lisi;
Query OK, 0 rows affected (0.00 sec)
使用数据库
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
查看当前使用的数据库
mysql> select database();
+------------+
| database() |
+------------+
| mysql |
+------------+
1 row in set (0.00 sec)
创建用户
mysql> create user 'zhangsan'@'host' identified by 'zhangsan';
Query OK, 0 rows affected (0.01 sec)
也可以用如下方法创建用户
mysql> grant all on lisi.* to 'lisi'@'localhost' identified by 'root@123';
Query OK, 0 rows affected, 1 warning (0.00 sec)
删除用户
mysql> drop user 'zhangsan'@'host';
Query OK, 0 rows affected (0.00 sec)
mysql> drop user 'lisi'@'localhost';
Query OK, 0 rows affected (0.00 sec)
mysql> select user,host from mysql.user\G
*************************** 1. row ***************************
user: mysql.session
host: localhost
*************************** 2. row ***************************
user: mysql.sys
host: localhost
*************************** 3. row ***************************
user: root
host: localhost
3 rows in set (0.00 sec)
这篇关于MySQL数据库基础操作的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2025-01-02MySQL 3主集群搭建
- 2024-12-25如何部署MySQL集群资料:新手入门教程
- 2024-12-24MySQL集群部署资料:新手入门教程
- 2024-12-24MySQL集群资料详解:新手入门教程
- 2024-12-24MySQL集群部署入门教程
- 2024-12-24部署MySQL集群学习:新手入门教程
- 2024-12-24部署MySQL集群入门:一步一步搭建指南
- 2024-12-07MySQL读写分离入门:轻松掌握数据库读写分离技术
- 2024-12-07MySQL读写分离入门教程
- 2024-12-07MySQL分库分表入门详解