数据库
首页 > 数据库> > MySQL数据库基础操作

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,lisi,sec,user,mysql,操作,0.00,row
来源: https://www.cnblogs.com/hailun1987/p/16368918.html