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数据库基础操作的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程